计算机网络自顶向下方法 习题参考答案 第二章

复习题

R1.

web:http;文件传输:FTP;邮件:SMTP;P2P:Bittorrent;远程登录:telnet

R2.

网络体系结构指的是五层模型,应用程序体系结构指的是 P2P 或者 客户-服务器

R3.

先发起对话的是客户,接收请求的是服务器

R4.

不同意,发送文件的对等方通常被称为服务器,接收文件的被称为客户

R5.

端口和 IP

R6.

UDP

R7.

QQ

R8.

  • 可靠数据传输:TCP 提供
  • 吞吐量:都不提供
  • 定时:都不提供
  • 安全性:都不提供

R9.

SSL 运行在应用层;
如果想要强化TCP,需要把 SSL 的代码写到程序里;
中文版的课本上写的是 UDP,UDP 不能用 SSL;

R10.

握手协议是指主要用来让客户端及服务器确认彼此的身份的一类网络协议

R11.

因为这些应用都需要可靠传输服务,而 UDP 不能提供

R12.

当用户初次访问网站时,服务器创建一个独一无二的标志数,在返回客户端的报文中发送给用户,这个数被称为 cookie,由浏览器维护;当用户请求查看购物车时,cookie 插在报文中被发送到服务器,服务器返回特定 cookie 对应的购物车信息

R13.

Web 缓存器中保存最近请求过的对象的副本。会减少所有对象的时延。

R14.

USER@NAME:~# telnet httpd.apache.org 80
Trying 40.79.78.1...
Connected to httpd.apache.org.
Escape character is '^]'.
GET /index.html HTTP/1.1
Host: httpd.apache.org
If-Modified-Since: Sat, 22 Sep 2018 11:41:57 GMT

HTTP/1.1 304 Not Modified
Date: Tue, 02 Oct 2018 07:19:28 GMT
Server: Apache/2.4.18 (Ubuntu)
ETag: "24ea-576743e4db26f"

R15.

FTP 有一条控制连接,一条数据连接

R16.

首先报文通过 HTTP 传送到 Alice 的邮件服务器,然后服务器通过 SMTP 将报文发送到 Bob 的服务器,然后 Bob 用 POP3 接收这个报文

R17.

手动打码 (ಡωಡ)

USER@NAME:~# telnet pop.163.com 110
Trying 123.125.50.29...
Connected to pop3.163.idns.yeah.net.
Escape character is '^]'.
+OK Welcome to coremail Mail Pop3 Server (163coms[b62aaa251425b4be4eaec4ab4744cf47s])
user ****@163.com
+OK core mail
pass ****
+OK 3 message(s) [9082 byte(s)]
list
+OK 3 9082
1 3406
2 2376
3 3300
.
TOP 1 0
+OK 3406 octets
Received: ****
Date: ****
From: ****
To:****@163.com
...

各头部信息可以参考 RFC 5321

R18.

下载并删除模式对用户来说是不友好的,用户无法第二次查看邮件
下载并保留模式是不方便的,因为很久远的邮件也会保留下来

R19.

Web服务器可以和邮件服务器有相同的别名
包含邮件服务器的 RR 是 MX

R20.

能确定,而 gmail 却不行

R21.

不需要,Alice 必须是 Bob 的上传速率最高的 4 个邻居

R22.

在 Bittorrent 中,对等方们每过 30 秒随机选择另外的一个邻居发送块,当 Alice 被随机选中时,她将得到第一个块

R23.

覆盖网络不包含路由器,是对等方组成的逻辑网络,不是物理链路,边是两个对等方之间有 TCP 连接。

R24.

网状 DHT:
优点很明显,大大减少用于查询的时间和报文数量
缺点是每个对等方必须追踪其他所有对等方

环形 DHT:
优点是追踪的对等方少
缺点是查询时间长,报文数量多

R25.

文件下载,即时讯息,网络直播,分布式计算

R26.

TCP 有一个欢迎套接字,一个连接套接字
n + 1

R27.

TCP 需要建立连接,UDP 不需要






习题

P1.

a.
b.
c.
d.
e.

P2.

FTP SERVICE COMMANDS:

         RETRIEVE (RETR)

         STORE (STOR)

         STORE UNIQUE (STOU)

         APPEND (with create) (APPE)

         ALLOCATE (ALLO)

         RESTART (REST)

         RENAME FROM (RNFR)

         RENAME TO (RNTO)

         ABORT (ABOR)

         DELETE (DELE)

         REMOVE DIRECTORY (RMD)

         MAKE DIRECTORY (MKD)

         PRINT WORKING DIRECTORY (PWD)

         LIST (LIST)

         NAME LIST (NLST)

         SITE PARAMETERS (SITE)

         SYSTEM (SYST)

         STATUS (STAT)

         HELP (HELP)

         NOOP (NOOP)

P3.

应用层:DNS HTTP
运输层:TCP(HTTP需要) UDP(DNS需要)

P4.

a.
gaia.cs.umass.edu/cs453/index.html

b.
1.1

c.
持续

d.
HTTP 报文中没有 IP 地址

e.
Mozilla/5.0 可以针对不同的浏览器发送不同版本的网页

P5.

a.

Tue, 07 Mar 2008 12:39:45 GMT

b.
Last-Modified: Sat, 10 Dec 2005 18:27:46 GMT

c.
Content-Length: 3874

d.
前五个字节:"<!doc"
根据 keep-alive 看出同意持续连接

P6.

a.

   An HTTP/1.1 server MAY assume that a HTTP/1.1 client intends to
   maintain a persistent connection unless a Connection header including
   the connection-token "close" was sent in the request. If the server
   chooses to close the connection immediately after sending the
   response, it SHOULD send a Connection header including the
   connection-token close.

   An HTTP/1.1 client MAY expect a connection to remain open, but would
   decide to keep it open based on whether the response from a server
   contains a Connection header with the connection-token close. In case
   the client does not want to maintain a connection for more than that
   request, it SHOULD send a Connection header including the
   connection-token close.

   If either the client or the server sends the close token in the
   Connection header, that request becomes the last one for the
   connection.

意思就是双方都可以关闭连接

b.
HTTP 并没有提供什么加密服务

c.

    Clients that use persistent connections SHOULD limit the number of
   simultaneous connections that they maintain to a given server. A
   single-user client SHOULD NOT maintain more than 2 connections with
   any server or proxy. A proxy SHOULD use up to 2*N connections to
   another server or proxy, where N is the number of simultaneously
   active users. These guidelines are intended to improve HTTP response
   times and avoid congestion.

意思是客户最多可以和给定服务器有两条并行连接

d.

    A client, server, or proxy MAY close the transport connection at any
   time. For example, a client might have started to send a new request
   at the same time that the server has decided to close the "idle"
   connection. From the server's point of view, the connection is being
   closed while it was idle, but from the client's point of view, a
   request is in progress.

意思是一侧关闭连接而另一侧正在传输数据是可能的。

P7.

得到IP地址的时间 = RTT1 + RTT2 + … + RTTn
三次握手加上最后的响应 = 2 RTT0
因此总共是 2 RTT0 + RTT1 + RTT2 + … + RTTn

P8.

a.
2RTT0 + RTT1 + RTT2 + … + RTTn + 8 * 2 RTT0 = 18 RTT0 + RTT1 + RTT2 + … + RTTn

b.
2RTT0 + RTT1 + RTT2 + … + RTTn + 2 * 2 RTT0 = 6 RTT0 + RTT1 + RTT2 + … + RTTn

c.
2RTT0 + RTT1 + RTT2 + … + RTTn + RTT0 = 3 RTT0 + RTT1 + RTT2 + … + RTTn

P9.

a.
Δ = 850000b / 15Mbps = 0.0567s
β = 16请求/s
t接 = Δ/1-Δβ = 0.61s
t总 = t接 + t因 = 3.61s

b.
英文版是不命中率为0.4,这里按中文版做:
β’ = 16请求/s * 60%
t接’ = Δ/1-Δβ = 0.12s
当命中缓存器时: t命 = 850000b / 100Mbps = 0.0085s
因此 t总’ = 0.4 * 0.0085 + 0.6(t接’ + t因) = 1.8754s

P10.

10米短链路,忽略其传播时延。

带有并行连接的非持续连接且并行下载:
(200b / 150bps) * 3 + ((10^5)b/ 150bps) + (200b / (150bps / 10)) * 3 + ((10^5)b / (150bps / 10)) = 7377.3s

持续连接:
(200b / 150bps) * 3 + ((10^5)b / 150bps) + 10 * (200b/150bps + (10^5)b/150bps) = 7351s

P11.

a.
毫无疑问,是可以的,这里不做证明

b.
仍然是可以的

P12.

服务器代码:

from socket import *
import threading
def Accept(ConnectionSocket, Addr):
	Message = ConnectionSocket.recv(1024).decode('utf-8', 'ignore')
	print(Message)
	ConnectionSocket.send('haha'.encode('utf-8', 'ignore')) 
	ConnectionSocket.close()

ServerPort = 10000
ServerSocket = socket(AF_INET, SOCK_STREAM) 
ServerSocket.bind(('',ServerPort))
ServerSocket.listen()
print('listening...')
while 1:
	ConnectionSocket, Addr = ServerSocket.accept() 
	t = threading.Thread(target=Accept, args=(ConnectionSocket, Addr))
	t.start()

比如我先访问 http://httpd.apache.org,然后打开服务器程序,在浏览器里设置服务器程序为代理,然后再用浏览器刷新一次,出现了以下报文,说明浏览器使用了条件GET报文。如果不成功,可能要多试几次。·

GET http://httpd.apache.org/ HTTP/1.1
Host: httpd.apache.org
...
If-Modified-Since: Sat, 22 Sep 2018 11:41:57 GMT
...

P13.

MAIL FROM 是 SMTP 握手协议的一部分,而 From 是邮件报文的一部分。

P14.

SMTP 使用仅包含一个句号的一行来标志报文体结束,HTTP 使用 Content-Length 标志。
不能,因为报文内容可能含有句号。

P15.

In particular, SMTP servers and clients provide a mail transport service
   and therefore act as "Mail Transfer Agents" (MTAs).  "Mail User
   Agents" (MUAs or UAs) are normally thought of as the sources and
   targets of mail.  At the source, an MUA might collect mail to be
   transmitted from a user and hand it off to an MTA; the final
   ("delivery") MTA would be thought of as handing the mail off to an
   MUA (or at least transferring responsibility to it, e.g., by
   depositing the message in a "message store").  However, while these
   terms are used with at least the appearance of great precision in
   other environments, the implied boundaries between MUAs and MTAs
   often do not accurately match common, and conforming, practices with
   Internet mail.  Hence, the reader should be cautious about inferring
   the strong relationships and responsibilities that might be implied
   if these terms were used elsewhere.

意思是 MTA(Mail Transfer Agents) 其实就是提供邮件传输服务的 SMTP 服务器和客户端。

When forwarding a message into or out of the Internet environment, a
   gateway MUST prepend a Received: line, but it MUST NOT alter in any
   way a Received: line that is already in the header section.

Received 是 在将消息转发到 Internet 环境或从 Internet 环境转发消息时,网关必须预先添加 Received 行,并且它不得以任何方式更改已在标题部分中的 Received 行。
因此排在最后面的 Received 行所指示的地址就是源地址,即 58.88.21.177

P16.

 which uniquely identifies a message within a
          maildrop and which persists across sessions. 

UIDL 即 unique-id listing,可以唯一定位一个消息

P17.

a.

list
+OK 3 14907
1 9125
2 3406
3 2376
.
retr 1
blah blah ...
..........blah
.
dele 1
+OK core mail
quit
+OK core mail

b.

list 
+OK 2 5782
2 3406
3 2376
.
retr 2
blah blah ...
..........blah
.
quit
+OK core mail

c.

list
+OK 2 5782
2 3406
3 2376
.
retr 3
blah blah ...
..........blah
.
retr 2
blah blah ...
..........blah
.
quit
+OK core mail

P18.

a.
whois(读作“Who is”,非缩写)是用来查询域名的IP以及所有者等信息的传输协议。简单说,whois就是一个用来查询域名是否已经被注册,以及注册域名的详细信息的数据库(如域名所有人、域名注册商)。通过whois来实现对域名信息的查询。早期的whois查询多以命令列接口存在,但是现在出现了一些网页接口简化的线上查询工具,可以一次向不同的数据库查询。网页接口的查询工具仍然依赖whois协议向服务器发送查询请求,命令列接口的工具仍然被系统管理员广泛使用。whois通常使用TCP协议43端口。每个域名/IP的whois信息由对应的管理机构保存。

b.
Name Server: ns2.google.com
Name Server: ns1.google.com
Name Server: ns4.google.com
Name Server: ns3.google.com
我用的是 linux 上的 whois 命令

c.
在 windows 打开 cmd,使用 nslookup 命令

nslookup 用法:
   nslookup [-opt ...]             # 使用默认服务器的交互模式
   nslookup [-opt ...] - server    # 使用 "server" 的交互模式
   nslookup [-opt ...] host        # 仅查找使用默认服务器的 "host"
   nslookup [-opt ...] host server # 仅查找使用 "server" 的 "host"
比如
nslookup -qt=mx 163.com ns6.nease.net
-qt 可以指示类型

d.

C:\>nslookup www.baidu.com
服务器:  *
Address:  *.*.*.*

非权威应答:
名称:    www.a.shifen.com
Addresses:  111.13.100.92
          111.13.100.91
Aliases:  www.baidu.com

可以看到百度有两个 web 地址

e.
自行查询吧

f.
攻击者可以通过 whois 和 nslookup 查询到目标的 IP 地址,DNS 服务器等

g.
whois 是用来查询域名的IP以及所有者等信息的传输协议,简单说,whois就是一个用来查询域名是否已经被注册,以及注册域名的详细信息的数据库(如域名所有人、域名注册商)。通过whois来实现对域名信息的查询。

P19.

a.
以下是 gaia.cs.umass.edu 的查询委托链路:
首先查询根服务器,然后总是选择第一个服务器,最后就可以查到 gaia.cs.umass.edu 的 IP 地址

# dig +norecurse @a.root-servers.net any gaia.cs.umass.edu
...
;; AUTHORITY SECTION:
edu.			172800	IN	NS	f.edu-servers.net.
edu.			172800	IN	NS	a.edu-servers.net.
edu.			172800	IN	NS	g.edu-servers.net.
edu.			172800	IN	NS	l.edu-servers.net.
edu.			172800	IN	NS	c.edu-servers.net.
edu.			172800	IN	NS	d.edu-servers.net.
...

# dig +norecurse @f.edu-servers.net any gaia.cs.umass.edu
...
;; AUTHORITY SECTION:
umass.edu.		172800	IN	NS	ns1.umass.edu.
umass.edu.		172800	IN	NS	ns3.umass.edu.
umass.edu.		172800	IN	NS	ns2.umass.edu.
...

# dig +norecurse @ns1.umass.edu any gaia.cs.umass.edu
...
;; ANSWER SECTION:
gaia.cs.umass.edu.	21600	IN	MX	0 barramail.cs.umass.edu.
gaia.cs.umass.edu.	21600	IN	A	128.119.245.12
...

b.
查询 google.com 时的链路,类似的:
a.edu-servers.net
a.gtld-servers.net
ns2.google.com

P20.

在一段时间内, DNS 服务器缓存中出现最频繁的 web 服务器就是最流行的

P21.

很简单,只需要输入这样的命令dig server,把 server 改成你想测试的网站名,如果 Query time 极短,说明最近可能有人访问过该网站。

P22.

客户-服务器:
与 u 无关, t = max{NF/us, F/di}

Nt
107500s
10050000s
1000500000s

P2P:
t = max{F/us, F/di, NF/(us+Nu)}

tN101001000
    u
300kps7500s25000s45454.5s
700kps7500s15000s20547.9s
2Mbps7500s7500s7500s

P23.

a.
服务器向每个客户端并行发送文件,此速率为 us/N,因为 us/N <= dmin,所以客户端也以该速率下载。则每个客户端接收完文件的时间为 F / (us / N) = NF / us

b.
仍然考虑服务器向每个客户端并行发送文件,以 dmin 为速率,因为 us/N >= dmin,所以 us >= Ndmin,故服务器可以承受此速率,各服务器以 dmin 为下载速率,故接收时间为 F/dmin

c.
当 us/N <= dmin 时:
        N/us >= 1/dmin
        NF/us >= F/dmin
        此时 t = NF/us = max{NF/us, F/dmin}
当 us/N >= dmin 时:
        N/us <= 1/dmin
        NF/us <= F/dmin
        此时 t = F/dmin = max{NF/us, F/dmin}

因此:得出最小分发时间为 max{NF/us,F/dmin}

P24.

太难了。。。。

P25.

N,N(N-1)/2

P26.

a.
这是可能的,BitTorrent 存在漏洞,不能防止不合作的搭便车行为。
比如 BitThief,它声称自己可以从 BitTorrent swarm 上下载却无需贡献任何资源

b.
他可以在每台主机上都运行客户端,并使他们搭便车,然后将它们收集的块聚合成一个文件,他还可以使不同主机下载不同的块,这是实际上一种 Sybil 攻击。

P27.

对等方 3 可以查它的第二后继对等方 4,使对等方 4 返回它的第一后继对等方 8。
对等方 3 的第一后继是对等方 4,第二后继是对等方 8

P28.

查询会顺时针一直到对等方 5,对等方 5 知道 6 要成为其后继, 6 的后继为 8, 然后 5 向 6 发送 6 的前后继信息,6 接收之后就可以加入 DHT 了。

P29.

对任意 key,可以计算它与所有对等方的距离,将其存放在距离它最近的对等方。

P30.

可能。随机分配标志符而不考虑物理链路,确实会造成错误匹配,逻辑上的“邻居”可能在物理上相距十万八千里。

P31.

a.
会出错

Traceback (most recent call last):
  File "./TCPclient.py", line 5, in <module>
    ClientSocket.connect((ServerName,ServerPort))
ConnectionRefusedError: [Errno 111] Connection refused

b.
没有什么影响

c.
TCP 肯定会报错

P32.

没有必要修改 UDPServer.py
源端口号 5432,目的端口号 12000
源端口号是随机的

P33.

可以,参考这篇博客 https://blog.csdn.net/williham/article/details/7251091

P34.

P35.

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。
它是自由软件。
它的一些功能:

    Loadable Dynamic Modules
    Multiple Request Processing modes (MPMs) including Event-based/Async, Threaded and Prefork.
    Highly scalable (easily handles more than 10,000 simultaneous connections)
    Handling of static files, index files, auto-indexing and content negotiation
    .htaccess support[17]
    Reverse proxy with caching[18]
        Load balancing[19] with in-band health checks
        Multiple load balancing mechanisms
        Fault tolerance and Failover with automatic recovery
        WebSocket, FastCGI, SCGI, AJP and uWSGI support with caching
        Dynamic configuration[20]
    TLS/SSL with SNI and OCSP stapling support, via OpenSSL.
    Name- and IP address-based virtual servers
    IPv6-compatible
    HTTP/2 protocol support
    Fine-grained authentication and authorization access control[21]
    gzip compression and decompression
    URL rewriting[22]
    Headers[23] and content[24][25] rewriting
    Custom logging with rotation
    Concurrent connection limiting
    Request processing rate limiting
    Bandwidth throttling
    Server Side Includes[26]
    IP address-based geolocation
    User and Session tracking[27]
    WebDAV
    Embedded Perl, PHP and Lua scripting
    CGI support[28]
    public_html per-user web-pages[29]
    Generic expression parser[30]
    Real-time status views[31]
    XML support[32]
    FTP support (by a separate module) [33]

P36.

键是 torrent 的 infohash,值是存有当前 infohash 指示的文件的 IP 地址

  • 112
    点赞
  • 600
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 28
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 28
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CHOOOU

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值