feat: 添加计算机网络课程的实验报告

This commit is contained in:
Chiyo Yuki 2025-09-11 09:50:03 +08:00 committed by KirisameVanilla
parent 6f0b23a38a
commit 18a6d9eaf7
No known key found for this signature in database
GPG Key ID: 7FC750F817277AC5
78 changed files with 1569 additions and 0 deletions

View File

@ -4,3 +4,17 @@ title: 计算机网络
!!! warning "施工中" !!! warning "施工中"
# 计算机网络
## 实验报告
- [lab1](./lab/lab1/lab1)
- [lab2 Ethernet](./lab/lab2/lib2)
- [lab3 IPV4](./lab/lab3/lib3)
- [lab4 ARP](./lab/lab4/lib4)
- [lab5 UDP](./lab/lab5/lib5)
- [lab2 TCP](./lab/lab6/lib6)
- [lab2 Socket Programming](./lab/lab7/lib7)
> 除第一个实验外,其余实验所用到的 `.pcapng` 文件均附在对应文件夹下

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

View File

@ -0,0 +1,122 @@
**华东师范大学软件学院实验报告**
**一、实验目的**
1. 学会使用curl与wget指令
2. 学会通过Wireshark获取数据包
3. 了解协议层数据包的结构
4. 学会计算并分析协议开销
**二、实验内容与实验步骤**
1. 在控制台中输入"curl <http://1st.moe/"并观察到"200> OK"
2. 启动Wireshark选择监听以太网并将捕获过滤器设置为tcp port
> 80关闭混杂模式并启用"enable network name resolution"选项
3. 关闭所有浏览器窗口后开始捕获
4. 重新在控制台输入"curl [**http://1st.moe/**](http://1st.moe/)"
5. 停止Wireshark捕获
**三、实验环境**
> B226机房电脑
**四、实验过程与分析**
1. 实验过程
1) 捕获内容如图所示
> ![](./Pictures/100000010000094B000002EADEAFEA2E.png){width="17.007cm"
> height="5.3cm"}
2. 1) 分析协议包的内容
> ![](./Pictures/10000001000003320000015C8A9E98EE.png){width="8.504cm"
> height="3.6cm"}![](./Pictures/100000010000032800000154F3640027.png){width="8.504cm"
> height="3.579cm"}![](./Pictures/100000010000032900000152B123680E.png){width="8.504cm"
> height="3.556cm"}![](./Pictures/100000010000033300000151977B0DF0.png){width="8.504cm"
> height="3.489cm"}
> 根据如上四张图片,可以发现各个协议所占的字节数为
+---------------------------------------+-------------+
| > 协议 | > 字节数 |
+---------------------------------------+-------------+
| > Ethernet (eth) | > 14 bytes |
+---------------------------------------+-------------+
| > Internet Protocol Version 6 (ipv6) | > 40 bytes |
+---------------------------------------+-------------+
| > Transmission Control Protocol (tcp) | > 20 bytes |
+---------------------------------------+-------------+
| > Hypertext Transfer Protocol (http) | > 128 bytes |
+---------------------------------------+-------------+
> 则包的结构大致如下
+-------------------+--------------------+------------+-------------+
| > eth | > ip | > tcp | > http |
+-------------------+--------------------+------------+-------------+
| > 14 bytes | > 40 bytes | > 20 bytes | > 128 bytes |
+-------------------+--------------------+------------+-------------+
| > Ethernet Header | > Ethernet Payload | | |
+-------------------+--------------------+------------+-------------+
| > IP Header | > IP Payload | | |
+-------------------+--------------------+------------+-------------+
3. 问题
1) 分析协议开销
> 一个GET本身的大小为128
> bytes而其相应产生的SYN、ACK请求也应算入其开销中。根据图片
> ![](./Pictures/10000001000004EE0000005E50C8B369.png){width="17.096cm"
> height="1.281cm"}
> 可以计算得出由于协议产生的总开销为86+74+(202-128)+74=308
> bytes从而计算得出比值约为0.4156,考虑到信息传输的稳定性,协议开销是值得的。
4. 1) 以太网头部中哪一部分是解复用键并且告知它的下一个高层指的是IP在这一包内哪一个值可以表示IP
> 根据图片
> ![](./Pictures/10000001000004000000007864293250.png){width="17.096cm"
> height="2.009cm"}
> ![](./Pictures/1000000100000470000000F4B4E41AC7.png){width="17.096cm"
> height="3.667cm"}
> 可以直观看出ipv6对应的分解键为0x86ddtcp对应的分解键为6
5. 故障分析
> 在实验过程中出现了控制台有反馈但Wireshark没有捕获的情况经排查后发现是由于控制台指令输入错误误将http输入为https所致。
**五、实验结果总结**
1. 实验完成了对一个HTTP包的拆解与分析其大体结构大致如下
+-------------------+--------------------+------------+-------------+
| > Eth | > ip | > tcp | > http |
+-------------------+--------------------+------------+-------------+
| > 14 bytes | > 40 bytes | > 20 bytes | > 128 bytes |
+-------------------+--------------------+------------+-------------+
| > Ethernet Header | > Ethernet Payload | | |
+-------------------+--------------------+------------+-------------+
| > IP Header | > IP Payload | | |
+-------------------+--------------------+------------+-------------+
2. 实验通过curl指令与Wireshark软件完成在其中熟悉网络工具的使用并体会到其强大之处
3. 通过查询相关资料,了解开销、分解键等概念
**六、附录**
**无**

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -0,0 +1,250 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>&lt;center&gt;&#x534e;&#x4e1c;&#x5e08;&#x8303;&#x5927;&#x5b66;&#x8f6f;&#x4ef6;&#x5b66;&#x9662;&#x5b9e;&#x9a8c;&#x62a5;&#x544a;&lt;&sol;center&gt;</title>
<style>
/* From extension vscode.github */
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.vscode-dark img[src$=\#gh-light-mode-only],
.vscode-light img[src$=\#gh-dark-mode-only],
.vscode-high-contrast:not(.vscode-high-contrast-light) img[src$=\#gh-light-mode-only],
.vscode-high-contrast-light img[src$=\#gh-dark-mode-only] {
display: none;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
</style>
<style>
.task-list-item {
list-style-type: none;
}
.task-list-item-checkbox {
margin-left: -20px;
vertical-align: middle;
pointer-events: none;
}
</style>
<style>
:root {
--color-note: #0969da;
--color-tip: #1a7f37;
--color-warning: #9a6700;
--color-severe: #bc4c00;
--color-caution: #d1242f;
--color-important: #8250df;
}
</style>
<style>
@media (prefers-color-scheme: dark) {
:root {
--color-note: #2f81f7;
--color-tip: #3fb950;
--color-warning: #d29922;
--color-severe: #db6d28;
--color-caution: #f85149;
--color-important: #a371f7;
}
}
</style>
<style>
.markdown-alert {
padding: 0.5rem 1rem;
margin-bottom: 16px;
color: inherit;
border-left: .25em solid #888;
}
.markdown-alert>:first-child {
margin-top: 0
}
.markdown-alert>:last-child {
margin-bottom: 0
}
.markdown-alert .markdown-alert-title {
display: flex;
font-weight: 500;
align-items: center;
line-height: 1
}
.markdown-alert .markdown-alert-title .octicon {
margin-right: 0.5rem;
display: inline-block;
overflow: visible !important;
vertical-align: text-bottom;
fill: currentColor;
}
.markdown-alert.markdown-alert-note {
border-left-color: var(--color-note);
}
.markdown-alert.markdown-alert-note .markdown-alert-title {
color: var(--color-note);
}
.markdown-alert.markdown-alert-important {
border-left-color: var(--color-important);
}
.markdown-alert.markdown-alert-important .markdown-alert-title {
color: var(--color-important);
}
.markdown-alert.markdown-alert-warning {
border-left-color: var(--color-warning);
}
.markdown-alert.markdown-alert-warning .markdown-alert-title {
color: var(--color-warning);
}
.markdown-alert.markdown-alert-tip {
border-left-color: var(--color-tip);
}
.markdown-alert.markdown-alert-tip .markdown-alert-title {
color: var(--color-tip);
}
.markdown-alert.markdown-alert-caution {
border-left-color: var(--color-caution);
}
.markdown-alert.markdown-alert-caution .markdown-alert-title {
color: var(--color-caution);
}
</style>
</head>
<body class="vscode-body vscode-light">
<h1 id="华东师范大学软件学院实验报告"><center>华东师范大学软件学院实验报告</center></h1>
<table align="center">
<thead>
<tr>
<th style="text-align:left"><strong>实验课程:</strong> 计算机网络</th>
<th style="text-align:left"><strong>年级:</strong> 2024</th>
<th style="text-align:left"><strong>实验成绩:</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>实验名称:</strong> Ethernet</td>
<td style="text-align:left"><strong>姓名:</strong> 张春晓</td>
<td style="text-align:left"><strong>实验日期:</strong> 2024.11.29</td>
</tr>
<tr>
<td style="text-align:left"><strong>实验编号:</strong> 2</td>
<td style="text-align:left"><strong>学号:</strong> 10234507025</td>
<td style="text-align:left"><strong>实验时间:</strong> 2学时</td>
</tr>
</tbody>
</table>
<hr>
<h2 id="一实验目的">一、实验目的</h2>
<p>学习以太网帧的组成</p>
<h2 id="二使用内容与实验步骤">二、使用内容与实验步骤</h2>
<ol>
<li>捕获帧
<ol>
<li>对一个远程服务器使用 ping 指令发送信息,并检查是否有回复;</li>
<li>启动 Wireshark ,选择过滤 icmp ,开启“启用 MAC 名称解析”选项,开始捕获以太网帧;</li>
<li>重复第一步;</li>
<li>终止 ping 指令,返回 Wireshark 并停止捕获。</li>
</ol>
</li>
<li>检查捕获到的数据
<ol>
<li>选择捕获到的任意数据包,查看其结构与组成数据包字节的详细信息;</li>
<li>展开以太网报头字段并查看详细信息。</li>
</ol>
</li>
<li>以太网帧结构
绘制一个显示以太网头字段位置与大小的 ping 报文图。</li>
<li>以太网地址范围
绘制一张图,显示电脑、路由器、远程服务器的相对位置。<br>
用以太网地址标注计算机与路由器IP 地址标注计算机与远程服务器。<br>
并显示以太网和互联网其他部分在图中的位置。</li>
<li>广播帧
启动 Wireshark ,选择过滤 ether multicast ,等待一段时间,捕获广播与组播以太网帧,并根据结果完成以下两个任务:<br>
<ol>
<li>找到广播以太网地址</li>
<li>找到以太网地址的哪一位确认是单播还是组播</li>
</ol>
</li>
</ol>
<h2 id="三实验环境">三、实验环境</h2>
<ul>
<li>实验仪器ThinkPad X230i</li>
<li>操作系统Arch GNU/Linux x86_64</li>
<li>以太网控制器Intel Corporation 82575LM Gigabit Network Connection</li>
<li>网络控制器Realtek Semiconductor Co., Ltd. RTL8188CE 820.11b/g/n WiFi Adapter</li>
<li>网络连接校园网ECNU-1X</li>
</ul>
<h2 id="四实验过程与分析">四、实验过程与分析</h2>
<ol>
<li>捕获帧<br>
<img src="file:////home/chiyoyuki/homework/conputer_network/lib3-1.png" alt="ping"><br>
<img src="file:////home/chiyoyuki/homework/conputer_network/lib3-2.png" alt="Wireshark"></li>
<li>检查捕获到的数据<br><br>
<img src="file:////home/chiyoyuki/homework/conputer_network/lib3-3.png" alt="ping"></li>
<li>以太网帧结构<br> <table align="center">
<tr>
<td align="center" colspan=3>Ethernet II</td>
<td align="center">IP&ICMP</td>
</tr>
<tr>
<td align="center">Destination</td>
<td align="center">Source</td>
<td align="center">Type</td>
<td align="center" rowspan=2>60 Bytes</td>
</tr>
<tr>
<td align="center">6 Bytes</td>
<td align="center">6 Bytes</td>
<td align="center">2 Bytes</td>
</tr>
<tr>
<td align="center" colspan=3>Ethernet Header</td>
<td align="center">Ethernet Payload</td>
<tr>
</table>
</li>
<li>以太网地址范围<br>
<img src="file:////home/chiyoyuki/homework/conputer_network/lib2-5.png" alt="mermaid"></li>
<li>广播帧
捕获内容如图:<br>
<img src="file:////home/chiyoyuki/homework/conputer_network/lib3-4.png" alt="broadcast"><br>
<ol>
<li>以太网地址为 ff:ff:ff:ff:ff:ff在 Wireshark 中标注为 Broadcast</li>
<li>第一个字节的末位为1是组播反之则是单播所有比特均为1则是广播</li>
</ol>
</li>
</ol>
<h2 id="五试验结果总结">五、试验结果总结</h2>
<p>在本次实验中,我顺利地完成了各项任务,了解并学习到了以太网传输的各项细节</p>
</body>
</html>

View File

@ -0,0 +1,81 @@
# <center>华东师范大学软件学院实验报告</center>
| **实验课程:** 计算机网络 | **年级:** 2024 | **实验成绩:** |
| :------------------------ | :--------------------- | :------------------------ |
| **实验名称:** Ethernet | **姓名:** | **实验日期:** 2024.11.29 |
| **实验编号:** 2 | **学号:** | **实验时间:** 2学时 |
---
## 一、实验目的
学习以太网帧的组成
## 二、使用内容与实验步骤
1. 捕获帧
1. 对一个远程服务器使用 ping 指令发送信息,并检查是否有回复;
2. 启动 Wireshark ,选择过滤 icmp ,开启“启用 MAC 名称解析”选项,开始捕获以太网帧;
3. 重复第一步;
4. 终止 ping 指令,返回 Wireshark 并停止捕获。
2. 检查捕获到的数据
1. 选择捕获到的任意数据包,查看其结构与组成数据包字节的详细信息;
2. 展开以太网报头字段并查看详细信息。
3. 以太网帧结构
绘制一个显示以太网头字段位置与大小的 ping 报文图。
4. 以太网地址范围
绘制一张图,显示电脑、路由器、远程服务器的相对位置。<br>
用以太网地址标注计算机与路由器IP 地址标注计算机与远程服务器。<br>
并显示以太网和互联网其他部分在图中的位置。
5. 广播帧
启动 Wireshark ,选择过滤 ether multicast ,等待一段时间,捕获广播与组播以太网帧,并根据结果完成以下两个任务:<br>
1. 找到广播以太网地址
2. 找到以太网地址的哪一位确认是单播还是组播
## 三、实验环境
- 实验仪器ThinkPad X230i
- 操作系统Arch GNU/Linux x86\_64
- 以太网控制器Intel Corporation 82575LM Gigabit Network Connection
- 网络控制器Realtek Semiconductor Co., Ltd. RTL8188CE 820.11b/g/n WiFi Adapter
- 网络连接校园网ECNU-1X
## 四、实验过程与分析
1. 捕获帧<br>
![ping](./lib3-1.png)<br>
![Wireshark](./lib3-2.png)
2. 检查捕获到的数据<br>
![ping](./lib3-3.png)
3. 以太网帧结构<br>
<table align="center">
<tr>
<td align="center" colspan=3>Ethernet II</td>
<td align="center">IP&ICMP</td>
</tr>
<tr>
<td align="center">Destination</td>
<td align="center">Source</td>
<td align="center">Type</td>
<td align="center" rowspan=2>60 Bytes</td>
</tr>
<tr>
<td align="center">6 Bytes</td>
<td align="center">6 Bytes</td>
<td align="center">2 Bytes</td>
</tr>
<tr>
<td align="center" colspan=3>Ethernet Header</td>
<td align="center">Ethernet Payload</td>
<tr>
</table>
4. 以太网地址范围<br>
![mermaid](./lib2-5.png)
5. 广播帧
捕获内容如图:<br>
![broadcast](./lib3-4.png)<br>
1. 以太网地址为 ff:ff:ff:ff:ff:ff在 Wireshark 中标注为 Broadcast
2. 第一个字节的末位为1是组播反之则是单播所有比特均为1则是广播
## 五、试验结果总结
在本次实验中,我顺利地完成了各项任务,了解并学习到了以太网传输的各项细节

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -0,0 +1,9 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
printf("%x",0x4500+0x0034+0xd124+0x4000+0x2606+0xe0f4+0x344a+0xe83b+0xda06+0xac1e);
return 0;
}

View File

@ -0,0 +1,31 @@
traceroute to 1st.moe (52.74.232.59), 30 hops max, 60 byte packets
1 * * *
2 10.100.5.1 (10.100.5.1) 8.795 ms 8.962 ms 9.096 ms
3 202.120.95.246 (202.120.95.246) 9.451 ms 9.092 ms 9.243 ms
4 202.120.95.254 (202.120.95.254) 12.480 ms 12.777 ms 13.331 ms
5 10.255.16.1 (10.255.16.1) 12.974 ms 13.249 ms 12.734 ms
6 10.255.249.253 (10.255.249.253) 12.382 ms 11.127 ms 11.127 ms
7 10.255.38.254 (10.255.38.254) 10.087 ms 9.632 ms 9.452 ms
8 202.112.27.13 (202.112.27.13) 9.268 ms 6.546 ms 6.331 ms
9 101.4.117.58 (101.4.117.58) 6.248 ms 9.316 ms 9.147 ms
10 * * *
11 101.4.115.250 (101.4.115.250) 37.316 ms 37.288 ms 36.908 ms
12 * * *
13 * * 101.4.114.194 (101.4.114.194) 33.724 ms
14 101.4.114.170 (101.4.114.170) 38.219 ms 101.4.117.102 (101.4.117.102) 44.767 ms 44.589 ms
15 101.4.114.222 (101.4.114.222) 67.753 ms 67.658 ms 63.246 ms
16 203.131.254.213 (203.131.254.213) 85.750 ms 85.593 ms 85.431 ms
17 203.131.242.222 (203.131.242.222) 67.546 ms 67.933 ms 67.157 ms
18 52.93.157.242 (52.93.157.242) 67.671 ms 52.93.157.226 (52.93.157.226) 67.991 ms 68.002 ms
19 52.93.35.125 (52.93.35.125) 67.392 ms 52.93.35.109 (52.93.35.109) 68.086 ms 52.93.35.35 (52.93.35.35) 68.009 ms
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *

View File

@ -0,0 +1,153 @@
# <center>华东师范大学软件学院实验报告</center>
| **实验课程:** 计算机网络 | **年级:** 2024 | **实验成绩:** |
| :------------------------ | :--------------------- | :------------------------ |
| **实验名称:** IPV4 | **姓名:** | **实验日期:** 2024.12.08 |
| **实验编号:** 3 | **学号:** | **实验时间:** 2学时 |
## 一、实验目的
学习 IP 协议的相关内容
## 二、使用内容与实验步骤
1. 捕获轨迹
1. 对一个远程服务器使用 wget/curl 指令,并检查是否成功;
2. 对同一远程服务器使用 traceroute 指令,查看访问的路径;
3. 启动 Wireshark ,选择过滤 tcp port 80 ,并勾选“启用网络名称检查”
4. 重复第一步
5. 返回 Wireshark ,停止捕获。
2. 检查捕获到的数据
1. 选择任意捕获到的数据包,查看其结构与组成数据包字节的详细信息;
2. 展开 IP 报头字段并查看详细信息。
3. IP 结构
1. 绘制一个 IP 字段位置与大小的报文图
2. 回答下列问题
1. 电脑与远程服务端的 IP 地址分别是多少?
2. 总长字段包括 IP 报头与 IP 负载还是仅计算 IP 负载?
3. 对于不同数据包,标识字段的值是不同还是相同?
4. 电脑发送的数据包的 TTL 字段的初始值是什么?是最大可能值还是一个较小的值?
5. 如何通过查看数据包确认其是否被分段?
6. IP 报头长度是多少,它如何在报头字段中编码?
4. IP 路径
绘制 1.2 步骤中访问的路径
5. IP 报头校验
通过如下步骤检验 IP 报头校验和是否正确
1. 将报头划分为等长的 10 段,每段长度为 2 个字节,将其视为 10 个十六进制数字;
2. 将 10 个 16 进制数字相加,计算他们的和;
3. 将得到的和分为两段,使得其中的一段为最右边的 4 位 16 进制数,计算两段之和;
4. 检查结果是否为 0xffff 。
## 三、实验环境
- 实验仪器ThinkPad X230i
- 操作系统Arch GNU/Linux x86\_64
- 以太网控制器Intel Corporation 82575LM Gigabit Network Connection
- 网络控制器Realtek Semiconductor Co., Ltd. RTL8188CE 820.11b/g/n WiFi Adapter
- 网络连接校园网ECNU-1X
## 四、实验过程与分析
1. 捕获轨迹
![wget](./lib3/lib3-2.png)
traceroute 获取到的信息如下:
```
traceroute to 1st.moe (52.74.232.59), 30 hops max, 60 byte packets
1 * * *
2 10.100.5.1 (10.100.5.1) 8.795 ms 8.962 ms 9.096 ms
3 202.120.95.246 (202.120.95.246) 9.451 ms 9.092 ms 9.243 ms
4 202.120.95.254 (202.120.95.254) 12.480 ms 12.777 ms 13.331 ms
5 10.255.16.1 (10.255.16.1) 12.974 ms 13.249 ms 12.734 ms
6 10.255.249.253 (10.255.249.253) 12.382 ms 11.127 ms 11.127 ms
7 10.255.38.254 (10.255.38.254) 10.087 ms 9.632 ms 9.452 ms
8 202.112.27.13 (202.112.27.13) 9.268 ms 6.546 ms 6.331 ms
9 101.4.117.58 (101.4.117.58) 6.248 ms 9.316 ms 9.147 ms
10 * * *
11 101.4.115.250 (101.4.115.250) 37.316 ms 37.288 ms 36.908 ms
12 * * *
13 * * 101.4.114.194 (101.4.114.194) 33.724 ms
14 101.4.114.170 (101.4.114.170) 38.219 ms 101.4.117.102 (101.4.117.102) 44.767 ms 44.589 ms
15 101.4.114.222 (101.4.114.222) 67.753 ms 67.658 ms 63.246 ms
16 203.131.254.213 (203.131.254.213) 85.750 ms 85.593 ms 85.431 ms
17 203.131.242.222 (203.131.242.222) 67.546 ms 67.933 ms 67.157 ms
18 52.93.157.242 (52.93.157.242) 67.671 ms 52.93.157.226 (52.93.157.226) 67.991 ms 68.002 ms
19 52.93.35.125 (52.93.35.125) 67.392 ms 52.93.35.109 (52.93.35.109) 68.086 ms 52.93.35.35 (52.93.35.35) 68.009 ms
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
```
2.
![wget](./lib3/lib3-2.png)
3.
1. IP结构
<table align="center">
<tr>
<td align="center" colspan=12>IP</td>
<td align="center">TCP</td>
</tr>
<tr>
<td align="center">Version</td>
<td align="center">Header Length</td>
<td align="center">Differentiated
Services Field</td>
<td align="center">Total Length</td>
<td align="center">Identification</td>
<td align="center">Flags</td>
<td align="center">Fragment Offset</td>
<td align="center">TTL</td>
<td align="center">Protocal</td>
<td align="center">Header Checksum</td>
<td align="center">Source Address</td>
<td align="center">Destinatoin Address</td>
<td align="center" rowspan=2>32 Bytes</td>
</tr>
<tr>
<td align="center">4 bits</td>
<td align="center">4 bits</td>
<td align="center">1 Byte</td>
<td align="center">2 Bytes</td>
<td align="center">2 Bytes</td>
<td align="center">3 bits</td>
<td align="center">13 Bits</td>
<td align="center">1 Byte</td>
<td align="center">1 Byte</td>
<td align="center">2 Bytes</td>
<td align="center">4 Bytes</td>
<td align="center">4 Bytes</td>
</tr>
<tr>
<td align="center" colspan=12>Ethernet Header</td>
<td align="center">Ethernet Payload</td>
<tr>
</table>
2.
1. 服务端 IP 地址为 52.74.232.59;电脑 IP 地址为 172.30.218.6
2. 总长字段为 52 = 20 + 32 ,所以计算时包含 IP 报头与 IP 负载
3. 不同
4. 电脑发送的 TTL 值为 38 ,是一个较小的值
5. 通过查看 Flags 字段
6. 长度为 20 Bytes ,编码在 IP 报头第一个字节的 4~8 位
4.
![wget](./lib3/lib3-3.png)
5. 执行如下代码:
```
#include<bits/stdc++.h>
using namespace std;
int main()
{
printf("%x",0x4500+0x0034+0xd124+0x4000+0x2606+0xe0f4+0x344a+0xe83b+0xda06+0xac1e);
return 0;
}
```
其结果为0x4fffb计算4+fffb=ffff故正确。

View File

@ -0,0 +1 @@
_gateway (172.31.0.1) at 54:c6:ff:7b:38:02 [ether] on wlan0

View File

@ -0,0 +1 @@
No ARP entry for 172.31.0.1

View File

@ -0,0 +1,26 @@
enp0s25: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 3c:97:0e:27:a3:96 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf2500000-f2520000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1511 bytes 158325 (154.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1511 bytes 158325 (154.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.31.215.159 netmask 255.255.0.0 broadcast 172.31.255.255
inet6 fe80::eb67:d196:62b:626a prefixlen 64 scopeid 0x20<link>
ether e0:06:e6:c4:be:04 txqueuelen 1000 (Ethernet)
RX packets 4206 bytes 2310892 (2.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4771 bytes 2531632 (2.4 MiB)
TX errors 0 dropped 76 overruns 0 carrier 0 collisions 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

View File

@ -0,0 +1,105 @@
# <center>华东师范大学软件学院实验报告</center>
| **实验课程:** 计算机网络 | **年级:** 2024 | **实验成绩:** |
| :------------------------ | :--------------------- | :------------------------ |
| **实验名称:** ARP | **姓名:** | **实验日期:** 2024.12.13 |
| **实验编号:** 4 | **学号:** | **实验时间:** 2学时 |
## 一、实验目的
了解 ARP 的工作原理。
## 二、使用内容与实验步骤
1. 捕获
1. 使用`ifconfig`指令查找电脑的以太网地址。
2. 使用`route`指令查看默认网关 ip 地址。
3. 启动 Wireshark ,将过滤器设置为`arp`,开始捕获。
4. 使用`arp -a`指令查看 ARP 缓存,并使用`sudo arp -d 网关ip地址`从缓存中清除默认网关。
5. 使用浏览器浏览网页一段时间。
6. 在捕获到 arp 流量后停止捕获。
2. 检查捕获
1. 将页面内的过滤器设置为`eth.addr == 电脑以太网地址`。
2. 查看捕获到的内容
3. ARP 请求与应答
绘制计算机与默认网关之间发送 ARP 请求与回复数据包的图解。
4. 以太网上的 ARP 详细信息
回答以下问题
1. 什么操作码用于请求,什么操作码用于回复。
2. 请求的 ARP 报头有多大?回复的 ARP 报头有多大?
3. 对于未知目标 MAC 地址的请求中携带什么值?
4. 什么以太网类型值表明 ARP 是更高级协议?
5. ARP 回复是否为广播?
## 三、实验环境
- 实验仪器ThinkPad X230i
- 操作系统Arch GNU/Linux x86\_64
- 以太网控制器Intel Corporation 82575LM Gigabit Network Connection
- 网络控制器Realtek Semiconductor Co., Ltd. RTL8188CE 820.11b/g/n WiFi Adapter
- 网络连接校园网ECNU-1X
## 四、实验过程与分析
1. 捕获
1. 执行`ifconfig`指令,得到的输出如下:
```
enp0s25: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 3c:97:0e:27:a3:96 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf2500000-f2520000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1511 bytes 158325 (154.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1511 bytes 158325 (154.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.31.215.159 netmask 255.255.0.0 broadcast 172.31.255.255
inet6 fe80::eb67:d196:62b:626a prefixlen 64 scopeid 0x20<link>
ether e0:06:e6:c4:be:04 txqueuelen 1000 (Ethernet)
RX packets 4206 bytes 2310892 (2.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4771 bytes 2531632 (2.4 MiB)
TX errors 0 dropped 76 overruns 0 carrier 0 collisions 0
```
`wlan0` 下的 `ether` 一行可以得知计算机以太网地址为 `e0:06:e6:c4:be:04`
2. 执行 `route` 指令,得到的输出如下:
```
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 600 0 0 wlan0
172.31.0.0 0.0.0.0 255.255.0.0 U 600 0 0 wlan0
```
可以得知默认网关的 ip 地址为 `172.31.0.0`
3. 启动捕获。
4. 执行 `arp -a` 指令,得到输出 `_gateway (172.31.0.1) at 54:c6:ff:7b:38:02 [ether] on wlan0` 。随后执行 `sudo arp -d 172.31.0.1` 指令清除缓存,该指令没有输出,若重复执行,则会得到 `No ARP entry for 172.31.0.1` 输出。
5. 在观察到已经捕获 7 个 ARP 流量包后停止捕获,其界面如图:<br>
![arp](./lib4-1.png)
2. 检查捕获<br>
*因为捕获到的包数量较少,故不设置过滤器。*<br>
请求包:<br>
![request](./lib4-2.png)
回复包:<br>
![reply](./lib4-3.png)
3. ARP 请求与回复
其图例如下
```mermaid
flowchart LR
computer[计算机<br>MAC e0:06:e6:c4:be:04<br>IP 172.31.215.159]
gateway[网关<br>MAC 54:c6:ff:7b:38:02<br>IP 172.31.0.1]
computer--request<br>Who has 172.31.0.1? Tell 172.31.215.159-->gateway
gateway--reply<br>172.31.0.1 is at <font color="red"><b>54:c6:ff:7b:38:02</b></font>-->computer
```
4. 以太网上的 ARP 详细信息
1. 请求的操作码为 `0x0001` ,回复的操作码为 `0x0002`
2. 请求与回复的的 ARP 报头均为 28 bytes对于报文请求的报文为 42 bytes回复的报文为60 bytes。
3. 目标 MAC 地址为 `00:00:00_00:00:00`
4. 以太网报头中的 `type` 字段为 `0x0806`
5. ARP 回复为单播而非广播。

View File

@ -0,0 +1,4 @@
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 600 0 0 wlan0
172.31.0.0 0.0.0.0 255.255.0.0 U 600 0 0 wlan0

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

View File

@ -0,0 +1,81 @@
# <center>华东师范大学软件学院实验报告</center>
| **实验课程:** 计算机网络 | **年级:** 2024 | **实验成绩:** |
| :------------------------ | :--------------------- | :------------------------ |
| **实验名称:** UDP | **姓名:** | **实验日期:** 2024.12.20 |
| **实验编号:** 5 | **学号:** | **实验时间:** 2学时 |
## 一、实验目的
学习 UDP 的构成等详细信息。
## 二、使用内容与实验步骤
1. 捕获
1. 启动 Wireshark 关闭混杂将过滤器设置为“udp”开始捕获。
2. 浏览网页以产生 UDP 流量。
3. 停止浏览,等待一分钟左右观察背景 UDP 流量。
4. 停止捕获。
2. 检查捕获到的数据<br>
观察所捕获到的流量包UDP 协议包包括如下字段:源端口、目标端口、长度、校验和。<br>
**注意:协议列所列出的协议可能是 UDP 之上的应用程序协议名称而非 UDP**
3. UDP 消息结构<br>
制作一份 UDP 报文图例并回答如下问题:<br>
1. 长度字段包含什么?
1. UDP 有效负载
2. UDP 有效负载与 UDP 报头
3. UDP 有效负载、UDP 报头与底层报头
2. UDP 校验和的长度为多少?(以位为单位)
3. UDP 报头的长度为多少字节?
4. UDP 使用<br>
回答如下问题:<br>
1. 给出标识上层协议为 UDP 的 IP 协议字段的值
2. 检查 UDP 消息并提供**当电脑既不是源IP地址也不是目标IP地址时**使用的目标 IP 地址
3. 捕获到的 UDP 消息的典型大小为多少
## 三、实验环境
- 实验仪器ThinkPad X230i
- 操作系统Arch GNU/Linux x86\_64
- 以太网控制器Intel Corporation 82575LM Gigabit Network Connection
- 网络控制器Realtek Semiconductor Co., Ltd. RTL8188CE 820.11b/g/n WiFi Adapter
- 网络连接校园网ECNU-1X
## 四、实验过程与分析
1. 捕获
本步骤采用老师所提供的捕获文件
2. 检查捕获到的数据
捕获包如图所示<br>
![package](./lib5-1.png)
3. UDP 消息结构<br>
观察下图所列出的包<br>
![struct](./lib5-2.png)
1. UDP 报头为 8 bytes负载为 143 bytes二者之和恰为 UDP 长度字段所标注的 151 bytes故 UDP 长度字段包括 **UDP 有效负载与 UDP 报头**
2. UDP 校验和的长度为 2 bytes即 16 位。
3. UDP 报头的长度为 8 bytes。
UDP 报文结构如下表所示:<br>
<table align="center">
<tr>
<td align="center" colspan=4>UDP Header</td>
<td align="center">UDP Payload</td>
</tr>
<tr>
<td align="center">Source Port</td>
<td align="center"> Destination Port</td>
<td align="center">Length</td>
<td align="center">Checksum</td>
<td align="center" rowspan=2> many bytes</td>
</tr>
<tr>
<td align="center">2 bytes</td>
<td align="center">2 bytes</td>
<td align="center">2 bytes</td>
<td align="center">2 bytes</td>
</tr>
</table>
4. UDP 使用
1. 如图所示IP 协议字段的值为 0x11 ,即 17<br>
![IP](lib5-3.png)
2. 如图所示,目标 IP 地址为 239.255.255.250<br>
![des](lib5-4.png)
3. 捕获到的 UDP 消息大小大多在 100 bytes 与 300 bytes 之间。

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

View File

@ -0,0 +1,234 @@
# <center>华东师范大学软件学院实验报告</center>
| **实验课程:** 计算机网络 | **年级:** 2024 | **实验成绩:** |
| :------------------------ | :--------------------- | :------------------------------------------ |
| **实验名称:** TCP | **姓名:** | **实验日期:** <br>2024.12.27<br>2025.01.03 |
| **实验编号:** 6 | **学号:** | **实验时间:** 2学时 |
## 一、实验目的
学习了解 TCP 的相关内容。
## 二、使用内容与实验步骤
1. 捕获
1. 找到一个可以使用 HTTP 下载的中等大小单一资源。
2. 使用 wget 或 curl 命令尝试下载,确保可以在几秒内下载至少 500 KB 的内容。
3. 启用 Wireshark ,将过滤器设置为 "tcp and host $DOMAIN" ,其中 $DOMAIN 为远程服务器的域名,并开始捕获。
4. 重复 1.2 中的命令。
5. 返回 Wireshark 并停止捕获。
2. 检查捕获到的内容
选择一个协议列为 TCP 的数据包,展开 TCP 协议部分。捕获到的内容中协议列除了初始 HTTP GET 和末尾的 HTTP 相应包之外均为 TCP 。在一个 TCP 包中,大致可以看到如下内容:
1. 源端口(可能为 80与目标端口。
2. 序列号字段,告知第一个有效负载字节在字节流中的位置。
3. 确认字段,告知反向字节流中最后接收的位置。
4. 报头长度TCP 报头的长度。
5. 标志字段。
6. 校验和,用于检查传输错误。
7. 选项字段。(可能不存在)
8. TCP 有效负载,表示正在传输的内容.(可能不存在)
3. TCP 段结构
绘制一个 TCP 段结构图。
4. TCP 建立与拆除。
- 三次握手
查找带有 SYN 标志的 TCP 段以及其后的数据包的详细信息。绘制三次握手的时间序列图,序列图应包括如下内容:
- 每个段上的序列号与 ACK 号(如果存在)
- 以毫秒为单位的时间
- 到服务器的往返时间估计,即 SYN 和 SYN-ACK 段之间的差值
- 连接选项
SYN 数据包中携带了哪些 TCP 选项。
- FIN/RST 拆除
查找带有 FIN 或 RES 标志的 TCP 段及其之后的数据包的详细信息。并绘制时间序列图,要求同三次握手的时间序列图。
5. TCP 数据传输
在统计菜单下选择“IO图表”观察并回答以下问题
1. TCP 连接运行良好后,下载方向的大致数据速率是多少(分别计算 packets/s 与 bits/s
2. 查看下载数据包,通过观察包的大小与 TCP 有效负载的大小,计算下载率中有多少百分比是内容?
3. 传输方向的大致数据速率是多少?
4. 如果最近从服务器接收的 TCP 段的序列号为 x ,那么下一个传输的 TCP 段携带什么 ACK 号?
检查捕获到的下载数据包是否具有如下特征:
- 延迟 ACK。
- 接受到的段的序列号增加,后续传输的段的 ACK 号也相应增加。
- 在初始获取之后,传输的段的序列号不增加,接收段上的 ACK 编号也不增加。
- 每个段都带有大于等于 0 的窗口信息。
## 三、实验环境
- 实验仪器ThinkPad X230i
- 操作系统Arch GNU/Linux x86\_64
- 以太网控制器Intel Corporation 82575LM Gigabit Network Connection
- 网络控制器Realtek Semiconductor Co., Ltd. RTL8188CE 820.11b/g/n WiFi Adapter
- 网络连接:校园网 ECNU-1X
## 四、实验过程与分析
1. 捕获
2. 检查捕获到的内容
捕获到的内容如图所示:
![wireshark](lib6-1.png)
3. TCP 段结构
<table align="center">
<tr>
<td align="center" colspan=20>TCP 报头</td>
<td align="center">TCP 负载</td>
</tr>
<tr>
<td align="center">源端口<td>
<td align="center">目标端口<td>
<td align="center">序列号<td>
<td align="center">确认号<td>
<td align="center">报头长度<td>
<td align="center">Flags<td>
<td align="center">窗口<td>
<td align="center">校验和<td>
<td align="center">紧急指针<td>
<td align="center">Options<td>
<td a序列号: 0, ACK号: 1lign="center">TCP Payloads</td>
</tr>
<tr>
<td align="center">2 bytes<td>
<td align="center">2 bytes<td>
<td align="center">4 bytes<td>
<td align="center">4 bytes<td>
<td align="center">4 bits<td>
<td align="center">12 bits<td>
<td align="center">2 bytes<td>
<td align="center">2 bytes<td>
<td align="center">2 bytes<td>
<td align="center">12 bytes<td>
<td align="center">Many bytes</td>
</tr>
</table>
4. TCP 建立与拆除。
- 三次握手
SYN及其之后包的信息如图所示
![SYN-ACK](lib6-3.png)
根据所得到的信息画图:
```mermaid
sequenceDiagram
autonumber
participant Client
participant Server
Client->>Server: 0th ms, SYN, 序列号: 0
Note left of Client: Δ = 96ms
Server->>Client: 96th ms, SYN-ACK, 序列号: 0, ACK号: 1
Client->>Server: 96th ms, ACK, 序列号: 1, ACK号: 1
```
- 连接选项
SYN 包具体信息如图所示:
![SYN](lib6-2.png)
故可以观察到 SYN 包携带的选项有:
- Maximum segment size(最大段大小)
- SACK permitted(SACK 许可)
- Timestamps(时间戳)
- NOP(无操作)
- Window sacle(窗口比例)
- FIN/RST 拆除
FIN及其之后包的信息如图所示
![FIN](lib6-4.png)
根据所得到的信息画图:
```mermaid
sequenceDiagram
autonumber
participant Client
participant Server
Client->>Server: 844th ms, FIN-ACK, 序列号: 237, ACK号: 256850
Note left of Client: Δ = 45ms
Server->>Client: 889th ms, FIN-ACK, 序列号: 256850, ACK号: 238
Client->>Server: 889th ms, ACK, 序列号: 238, ACK号: 256851
```
5. TCP 数据传输
IO 图表如图:
![IO](lib6-5.png)
![IO](lib6-6.png)
1. 下载方向的大致数据速率是
$$
\frac{\frac{1}{8}(18+35+13+8+46+23+28+21) packets}{0.1 s} = 240\ packets/s
$$
$$
\frac{\frac{1}{8}(185300+401500+149100+91780+527700+263900+321200+226600) bits}{0.1 s} =2708850\ bits/s
$$
2. 查看下载数据包,通过观察包的大小与 TCP 有效负载的大小,计算下载率中有多少百分比是内容?
$$
\frac{1368 bytes}{1434 bytes}=\frac{228}{239} \approx 95.40\%
$$
3. 传输方向的大致数据速率是
$$
\frac{\frac{1}{8}(16+29+13+8+32+10+23+22) packets}{0.1 s} = 191.25\ packets/s
$$
$$
\frac{\frac{1}{8}(8448+15310+6864+4224+16990+5280+12140+11620) bits}{0.1 s} =101095\ bits/s
$$
4. 如果最近从服务器接收的 TCP 段的序列号为 x ,那么下一个传输的 TCP 段携带什么 ACK 号?
**x+TCP 负载字节数**

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

View File

@ -0,0 +1,69 @@
/* Source: Peterson & Davie (2007), Computer Networks, a Systems Approach,
* 4th ed., Morgan Kaufmann, p. 34-35.
* Included stdlib.h, string.h, and strings.h so it compiles on Linux.
* Changed port from 5432 (postgresql) to 7701 (unassigned).
* - JLND Feb 7 2009
*/
#include<unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SERVER_PORT 7701
#define MAX_LINE 256
int
main(int argc, char * argv[])
{
FILE *fp;
struct hostent *hp;
struct sockaddr_in sin;
char *host;
char buf[MAX_LINE];
int s;
int len;
if (argc==2) {
host = argv[1];
}
else {
fprintf(stderr, "usage: simplex-talk host\n");
exit(1);
}
/* translate host name into peers IP address */
hp = gethostbyname(host);
if (!hp) {
fprintf(stderr, "simplex-talk: unknown host: %s\n", host);
exit(1);
}
/* build address data structure */
bzero((char *)&sin, sizeof(sin));
sin.sin_family = AF_INET;
bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
sin.sin_port = htons(SERVER_PORT);
/* active open */
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("simplex-talk: socket");
exit(1);
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
perror("simplex-talk: connect");
close(s);
exit(1);
}
/* main loop: get and send lines of text */
while (fgets(buf, sizeof(buf), stdin)) {
buf[MAX_LINE-1] = '\0';
len = strlen(buf) + 1;
send(s, buf, len, 0);
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,7 @@
./client localhost
client1
text from client1
client1 stop
^C
./client
usage: simplex-talk host

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

View File

@ -0,0 +1,288 @@
# <center>华东师范大学软件学院实验报告</center>
| **实验课程:** 计算机网络 | **年级:** 2024 | **实验成绩:** |
| :-------------------------------- | :--------------------- | :------------------------ |
| **实验名称:** Socket Programming | **姓名:** | **实验日期:** 2025.01.03 |
| **实验编号:** 7 | **学号:** | **实验时间:** 2学时 |
## 一、实验目的
了解套接字编程相关内容。
## 二、使用内容与实验步骤
使用实验手册中所给出的示例代码,并进行相关测试。
## 三、实验环境
- 实验仪器1ThinkPad X230i
- 操作系统6.12.9-arch1-1 x86_64 GNU/Linux
- 以太网控制器Intel Corporation 82575LM Gigabit Network Connection
- 网络控制器Realtek Semiconductor Co., Ltd. RTL8188CE 820.11b/g/n WiFi Adapter
- 实验仪器2raspberrypi 4B
- 操作系统6.6.47+rpt-rpi-v8 aarch64 GNU/Linux
- 网络连接:宿舍 Wifi
## 四、实验过程与分析
本地测试记录如下图:
![test0](./lib7-1.png)
实验步骤
1. 启动 Wireshark根据代码中常量定义将过滤选项设置为`tcp.port==7701`,对 `Loopback: lo` 进行捕获
2. 启动服务端
3. 启动0号客户端,此时 Wireshark 捕获到三次握手包观察到0号客户端采用44514端口
![png1](./lib7-2.png)
4. 发送文本测试
1. 0号客户端发送测试文本0测试短文本)`text0:hello, world`,服务端显示:`text0:hello, world`正常发送Wireshark 捕获到的包信息如下。
![png3](./lib7-3.png)
2. 0号客户端发送测试文本1测试ACSII可显示字符)text1: !"#\$%&'()\*+,-./0123456789:;<=>?\`ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^\_@abcdefghijklmnopqrstuvwxyz{|}~服务端显示text1: !"#\$%&'()\*+,-./0123456789:;<=>?\`ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^\_@abcdefghijklmnopqrstuvwxyz{|}~正常发送Wireshark 捕获到的包信息如下。
![png4](./lib7-4.png)
3. 0号客户端发送测试文本2测试tab字符)`text2:\t \t`,服务端显示:`text2:\t \t`正常发送Wireshark 捕获到的包信息如下。
![png5](./lib7-5.png)
可以观察到 tab 以正常形式ACSII码为9发出
4. 0号客户端发送测试文本3测试中文文本)`text3:你好,世界`,服务端显示:`text3:你好,世界`正常发送Wireshark 捕获到的包信息如下。
![png7](./lib7-7.png)
5. 0号客户端发送测试文本4测试长文本)`text4:0123456789abcdef...0123456789abcdef`共计32774字节服务端显示`text4:0123456789abcdef...012345678`共计4096字节文本发送不正常仅发送前 4096 字节,检查 Wireshark 可以发现0号客户端共发送16个包前15个包中每个包携带255字节的文本最后一个包携带16字节的文本捕获到的第一个与最后一个客户端包信息如下。
![png](./lib7-8.png)
可以观察到 IP 协议头中 DF 为 1 ,故数据未经 IP 分片,数据的分段发生在 TCP 加工阶段。
5. 断连测试
1. 断开0号客户端连接捕获到由0号客户端发出的结束请求
![png9](./lib7-9.png)
2. 重新恢复0号客户端连接
3. 断开服务端连接捕获到由服务端发出的结束请求FIN0号客户端发送ACK确认但未得到服务端的ACK确认于是0号客户端将在等待2MSL后自动断开连接捕获到的包信息如下
![png10](./lib7-10.png)
4. 0号客户端发送文本`a text from client` Wireshark 捕获到的内容如下
![png11](./lib7-11.png)
0号客户端发送了带有 PSH 的信息包端口收到后优先处理该数据包由于服务端已经关闭7701端口空闲故返回带有RST的数据报。
5. 0号客户端发送文本`server restart`按下回车后客户端自动退出Wireshark 没有捕获到消息
6. 执行指令`./client localhost`,尝试重新启动客户端,收到报错`simplex-talk: connect: Connection refused`,捕获到的包信息如下
![png12](./lib7-12.png)
0号客户端发送了带有 SYN 的信息包由于服务端已经关闭7701端口空闲故返回带有RST的数据报0号客户端收到后报告错误并退出
7. 执行指令`./client`,不指定地址,报错`usage: simplex-talk host`
6. 多客户端测试
1. 重新启动服务端
2. 启动0号客户端观察 Wireshark 可以发现0号客户端使用端口为53092
3. 0号客户端发送文本`client0`,服务端显示:`client0`,正常发送。
4. 启动1号客户端观察 Wireshark 可以发现1号客户端使用端口为43676Wireshark 捕获包信息如下:
![png13](./lib7-13.png)
5. 1号客户端发送文本`client1`,服务端没有显示,但 Wireshark 捕获到信息包。
6. 0号客户端发送文本`text from client0`,服务端显示`text from client0`,正常发送。
7. 1号客户端发送文本`text from client1`,服务端没有显示,但 Wireshark 捕获到信息包。
8. 0号客户端发送文本`client0 stop`,服务端显示`client0 stop`,正常发送。
9. 0号客户端断开连接服务端显示`client1`
10. 0号客户端发送文本`client1 stop`,服务端显示`client1 stop`,正常发送。
11. 断开服务端连接。
1 号客户端发送的三个携带文本的信息包如下:
![png14](./lib7-14.png)
7. 端口占用测试
1. 启动服务端Wireshark 未捕获到内容
2. 启动第二个服务端,报错`simplex-talk: bind: Address already in use`Wireshark 未捕获到内容
3. 启动客户端
4. 关闭服务端
5. 尝试重新启动服务端,报错`simplex-talk: bind: Address already in use`Wireshark 未捕获到内容
6. 客户端退出
7. 尝试重新启动服务端,服务端正常运行
测试截图如下:
![png15](./lib7-15.png)
8. 局域网通信测试
1. 通过 ssh 连接并控制同一局域网下的另一设备
2. 通过 ftp 上传源代码server.c与client.c
3. 在 ssh 所控制设备上编译
4. 启动 Wireshark ,将过滤器设置为`tcp.port == 7701`对wlan0进行捕获
5. 在远程主机上执行`./server`,在电脑上执行`./client 192.168.31.135`,成功连接
6. 在客户端上发送信息,远程服务端成功收到
7. 交换客户端与服务端,仍能成功通信
通信记录与 Wireshark 捕获截图如下:
![png16](./lib7-17.png)
![png18](./lib7-18.png)
## 五、附录
客户端代码如下:
```c
/* Source: Peterson & Davie (2007), Computer Networks, a Systems Approach,
* 4th ed., Morgan Kaufmann, p. 34-35.
* Included stdlib.h, string.h, and strings.h so it compiles on Linux.
* Changed port from 5432 (postgresql) to 7701 (unassigned).
* - JLND Feb 7 2009
*/
#include<unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SERVER_PORT 7701
#define MAX_LINE 256
int
main(int argc, char * argv[])
{
FILE *fp;
struct hostent *hp;
struct sockaddr_in sin;
char *host;
char buf[MAX_LINE];
int s;
int len;
if (argc==2) {
host = argv[1];
}
else {
fprintf(stderr, "usage: simplex-talk host\n");
exit(1);
}
/* translate host name into peers IP address */
hp = gethostbyname(host);
if (!hp) {
fprintf(stderr, "simplex-talk: unknown host: %s\n", host);
exit(1);
}
/* build address data structure */
bzero((char *)&sin, sizeof(sin));
sin.sin_family = AF_INET;
bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
sin.sin_port = htons(SERVER_PORT);
/* active open */
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("simplex-talk: socket");
exit(1);
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
perror("simplex-talk: connect");
close(s);
exit(1);
}
/* main loop: get and send lines of text */
while (fgets(buf, sizeof(buf), stdin)) {
buf[MAX_LINE-1] = '\0';
len = strlen(buf) + 1;
send(s, buf, len, 0);
}
}
```
服务端代码如下:
```c
/* Source: Peterson & Davie (2007), Computer Networks, a Systems Approach,
* 4th ed., Morgan Kaufmann, p. 35-36.
* Included stdlib.h, string.h, and strings.h so it compiles on Linux.
* Changed port from 5432 (postgresql) to 7701 (unassigned).
* - JLND Feb 7 2009
*/
#include<unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SERVER_PORT 7701
#define MAX_PENDING 5
#define MAX_LINE 256
int
main()
{
struct sockaddr_in sin;
char buf[MAX_LINE];
int len;
int s, new_s;
/* build address data structure */
bzero((char *)&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(SERVER_PORT);
/* setup passive open */
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("simplex-talk: socket");
exit(1);
}
if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0) {
perror("simplex-talk: bind");
exit(1);
}
listen(s, MAX_PENDING);
/* wait for connection, then receive and print text */
while(1) {
if ((new_s = accept(s, (struct sockaddr *)&sin, &len)) < 0) {
perror("simplex-talk: accept");
exit(1);
}
while (len = recv(new_s, buf, sizeof(buf), 0))
fputs(buf, stdout);
close(new_s);
}
}
```

View File

@ -0,0 +1,55 @@
/* Source: Peterson & Davie (2007), Computer Networks, a Systems Approach,
* 4th ed., Morgan Kaufmann, p. 35-36.
* Included stdlib.h, string.h, and strings.h so it compiles on Linux.
* Changed port from 5432 (postgresql) to 7701 (unassigned).
* - JLND Feb 7 2009
*/
#include<unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SERVER_PORT 7701
#define MAX_PENDING 5
#define MAX_LINE 256
int
main()
{
struct sockaddr_in sin;
char buf[MAX_LINE];
int len;
int s, new_s;
/* build address data structure */
bzero((char *)&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(SERVER_PORT);
/* setup passive open */
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("simplex-talk: socket");
exit(1);
}
if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0) {
perror("simplex-talk: bind");
exit(1);
}
listen(s, MAX_PENDING);
/* wait for connection, then receive and print text */
while(1) {
if ((new_s = accept(s, (struct sockaddr *)&sin, &len)) < 0) {
perror("simplex-talk: accept");
exit(1);
}
while (len = recv(new_s, buf, sizeof(buf), 0))
fputs(buf, stdout);
close(new_s);
}
}

View File

@ -0,0 +1,17 @@
./server
text0:hello, world
text1: !"#$%&'()*+,-./0123456789:;<=>?`ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_@abcdefghijklmnopqrstuvwxyz{|}~
text2:\t \t
text3:你好,世界
text4:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678
client0 stop
client0 restart
server stop
^C
./server
client0
text from client0
client0 stop
client1
client1 stop
^C

File diff suppressed because one or more lines are too long