計算機網絡自頂向下方法 習題參考答案 第二章

複習題

R1.

web:http;文件傳輸:FTP;郵件:SMTP;P2P:Bittorrent;遠程登陸:telnethtml

R2.

網絡體系結構指的是五層模型,應用程序體系結構指的是 P2P 或者 客戶-服務器python

R3.

先發起對話的是客戶,接收請求的是服務器linux

R4.

不一樣意,發送文件的對等方一般被稱爲服務器,接收文件的被稱爲客戶web

R5.

端口和 IPshell

R6.

UDP數據庫

R7.

QQexpress

R8.

  • 可靠數據傳輸:TCP 提供
  • 吞吐量:都不提供
  • 定時:都不提供
  • 安全性:都不提供

R9.

SSL 運行在應用層;
若是想要強化TCP,須要把 SSL 的代碼寫到程序裏;
中文版的課本上寫的是 UDP,UDP 不能用 SSL;apache

R10.

握手協議是指主要用來讓客戶端及服務器確認彼此的身份的一類網絡協議windows

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}

N t
10 7500s
100 50000s
1000 500000s

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

t N 10 100 1000
    u
300kps 7500s 25000s 45454.5s
700kps 7500s 15000s 20547.9s
2Mbps 7500s 7500s 7500s

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 地址