首页 > web技术 > 敲下g.cn之后的IP包

敲下g.cn之后的IP包

  • 本文链接地址:http://zhubaining.com/blog/2009/04/14/archives/what-happens-after-pressing-g-cn-and-enter
  • 作者:zhubaining

1. 环境:
OS: Windows XP.
Ethernet adapter 本地连接:

IP Address. . . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.
Default Gateway . . . . . . . . . : 192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.1
DNS Servers . . . . . . . . . . . : 192.168.1.1

PPP adapter 宽带连接:
IP Address. . . . . . . . . . . . : 125.34.55.250
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 125.34.55.250
DNS Servers . . . . . . . . . . . : 202.106.0.20
202.106.46.151
2. 准备好打家劫舍之利器:WireShark

3. 在浏览器的地址栏键入g.cn

4. 看看都收发了那些IP数据包:
ether向gw发出dns请求:为什么是两次呢?
1    0.000000    192.168.1.2    192.168.1.1    DNS    Standard query A g.cn
2    0.993684    192.168.1.2    192.168.1.1    DNS    Standard query A g.cn

adsl猫发出dns请求
3    0.993869    125.34.55.250    202.106.0.20    DNS    Standard query A g.cn

dns返回response:A 203.208.37.99 A 203.208.37.104
4    1.076265    202.106.0.20    125.34.55.250    DNS    Standard query response A 203.208.37.99 A 203.208.37.104

tcp三次握手
5    1.094284    125.34.55.250    203.208.37.99    TCP    dcs > http [SYN] Seq=0 Win=65535 Len=0 MSS=1326
6    1.106741    203.208.37.99    125.34.55.250    TCP    http > dcs [SYN, ACK] Seq=0 Ack=1 Win=5720 Len=0 MSS=1430
7    1.112781    125.34.55.250    203.208.37.99    TCP    dcs > http [ACK] Seq=1 Ack=1 Win=65535 Len=0

发出http get请求及对方的ack
8    1.120573    125.34.55.250    203.208.37.99    HTTP    GET / HTTP/1.1
9    1.139239    203.208.37.99    125.34.55.250    TCP    http > dcs [ACK] Seq=1 Ack=357 Win=6432 Len=0

服务器返回301
10    1.244680    203.208.37.99    125.34.55.250    HTTP    HTTP/1.1 301 Moved Permanently (text/html)

header:
HTTP/1.1 301 Moved Permanently
Location: http://www.google.cn/webhp?source=g_cn
Date: Mon, 13 Apr 2009 22:42:36 GMT
Expires: Mon, 13 Apr 2009 22:42:36 GMT
Cache-Control: private, max-age=2592000
Content-Type: text/html; charset=UTF-8
Server: gws
Content-Encoding: gzip
Transfer-Encoding: chunked

chunked的字节(下划线的是size):
共四组:第一组:63 38 => c8 => 200个字节
第二组:37 => 7 => 7个字节
第三组:61 => a => 10个字节
第四组(结尾):30 => 0 => 0个字节
0000   63 38 0d 0a 1f 8b 08 00 00 00 00 00 02 ff 4c 8f
0010   41 0b 82 40 10 85 ef 42 ff 61 d9 bb 6e d2 25 6a
0020   76 c3 c8 30 50 82 f0 d2 29 6c 9d dc 20 5d d3 31
0030   eb df a7 d5 a1 e3 7b f3 78 df 3c 88 d2 24 56 10
0040   85 c1 46 41 89 94 31 43 54 bb 78 ef ae 0f c9 b5
0050   ad 08 2b 72 e9 55 23 67 3f 25 39 e1 93 84 a1 f2
0060   b6 d4 26 6b 5a 24 d9 d1 c5 9d 73 e5 40 ba 4b e3
0070   50 cd a6 3e 4b ec 03 73 10 5f 03 c4 97 b0 de 6f
0080   8e 43 2a f2 ff 23 83 72 52 83 2c b7 ba 2b 07 00
0090   33 59 cb ca f1 e6 40 c0 a2 43 b8 95 7c fc 6a 21
00a0   44 df f7 5e 61 6d 71 43 4f 57 a2 c7 b3 a9 57 ad
00b0   ed 1a 8d b2 38 e9 8a 2b 83 0d 82 08 94 37 71 40
00c0   7c 68 43 ff 38 71 f2 06 00 00 ff ff 0d 0a 37 0d
00d0   0a e2 02 00 00 00 ff ff 0d 0a 61 0d 0a 03 00 41
00e0   34 b6 85 eb 00 00 00 0d 0a 30 0d 0a 0d 0a
chunked的数据是gzip的。
现在解压一下,就是:

<HTML><HEAD><meta http-equiv=”content-type” content=”text/html;charset=utf-8″>
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF=”http://www.google.cn/webhp?source=g_cn”>here</A>.
</BODY></HTML>

小插曲:
wireshark说“Content-encoded entity body (gzip): 217 bytes -> 235 bytes
”,而我把上面这些复制到UltraEdit里面一看是237字节,怎么不一致呢。原来只有上面标有下划线的两行是以0d0a结尾的,而其他的都是以0a结尾的。而放入UE里面的前5行都有0d0a,因此相差2个字节(即5个0d0a-4个0a-2个0d0a)。

dns请求:
11    1.284688    192.168.1.2    192.168.1.1    DNS    Standard query A www.google.cn

对上面的response的ack:
12    1.393979    125.34.55.250    203.208.37.99    TCP    dcs > http [ACK] Seq=357 Ack=546 Win=64990 Len=0

又发一次dns请求:
13    2.284645    192.168.1.2    192.168.1.1    DNS    Standard query A www.google.cn
14    2.284824    125.34.55.250    202.106.0.20    DNS    Standard query A www.google.cn

dns response:
15    2.299200    202.106.0.20    125.34.55.250    DNS    Standard query response CNAME google.cn A 203.208.39.104 A 203.208.39.99

tcp三次握手:
16    2.313014    125.34.55.250    203.208.39.104    TCP    screencast > http [SYN] Seq=0 Win=65535 Len=0 MSS=1326
17    2.325688    203.208.39.104    125.34.55.250    TCP    http > screencast [SYN, ACK] Seq=0 Ack=1 Win=5720 Len=0 MSS=1430
18    2.331428    125.34.55.250    203.208.39.104    TCP    screencast > http [ACK] Seq=1 Ack=1 Win=65535 Len=0

http get请求:
19    2.354894    125.34.55.250    203.208.39.104    HTTP    GET /webhp?source=g_cn HTTP/1.1
20    2.379580    203.208.39.104    125.34.55.250    TCP    http > screencast [ACK] Seq=1 Ack=794 Win=7137 Len=0

http response:
21    2.462698    203.208.39.104    125.34.55.250    TCP    [TCP segment of a reassembled PDU]
22    2.466654    203.208.39.104    125.34.55.250    TCP    [TCP segment of a reassembled PDU]
23    2.469674    203.208.39.104    125.34.55.250    HTTP    HTTP/1.1 200 OK (text/html)

对resonse的ack:
24    2.472140    125.34.55.250    203.208.39.104    TCP    screencast > http [ACK] Seq=794 Ack=2653 Win=65535 Len=0

发送http get,获取其中的image:
27    2.515103    125.34.55.250    203.208.39.104    HTTP    GET /intl/zh-CN/images/logo_cn.gif HTTP/1.1

get其他的资源比如js等…

另外:
1. ppp adatper 125.34.55.250
和外界的交互,都是将ip包用ppp协议(point-to-point protocol)包装起来的,而ether adapter 192.168.1.2和他的gw 192.168.1.1之间的交互不需要ppp。
2. 清除dns缓存:ipconfig /flushdns
3. nslookup中的命令:set debug/server/…

两个疑问:

1. 为什么dns请求都是发出两次?而且两次相隔的时间基本上是1s。
2. 为什么只有dns请求才显示为
ether adapter和gw的交互,而其他的都显示为ppp adapter与外界的交互?
3. dns返回结果不一样:用nslookup与浏览器直接访问时,dns的response不同。比如hi.baidu.com,前者返回三个A记录,后者返回一个CNAME(hi.n.shifen.com)和一个A记录(hi.n.shifen.com的IP)。

分类: web技术 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.