歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux網絡 >> Linux網絡抓包

Linux網絡抓包

日期:2017/3/1 16:15:34   编辑:Linux網絡
Linux網絡抓包 調試網絡程序時,通常需要抓包分析。Linux下的tcpdump就很好。 Ubuntu下默認已經安裝。下面先舉個實際的例子. 比如我有一個C++程序監聽本地端口8889, 另一個newlisp程序通過TCP和其通信。 首先可以檢查一下有幾個網絡接口。 [plain] root@dean-GA-MA790XT-UD4P:~# tcpdump -D 1.eth0 2.any (Pseudo-device that captures on all interfaces) 3.lo 由於是本機運行,都是通過lo接口,因此後面參數用-i 3. -i 3 代表監控的是網絡接口lo。 現在啟動tcpdump [plain] tcpdump -i 3 tcp port 8889 -v -XX -XX表示用16進制和ASCII文本顯示網絡包的數據。 [plain] 21:19:40.151304 IP (tos 0x0, ttl 64, id 37956, offset 0, flags [DF], proto TCP (6), length 56) localhost.8889 > localhost.55131: Flags [P.], cksum 0xfe2c (incorrect -> 0x8dc0), seq 41:45, ack 117, win 342, options [nop,nop,TS val 728981 ecr 723761], length 4 0x0000: 0000 0000 0000 0000 0000 0000 0800 4500 ..............E. 0x0010: 0038 9444 4000 4006 a879 7f00 0001 7f00 .8.D@[email protected]...... 0x0020: 0001 22b9 d75b 5a53 9f4c d8c4 bded 8018 .."..[ZS.L...... 0x0030: 0156 fe2c 0000 0101 080a 000b 1f95 000b .V.,............ 0x0040: 0b31 0100 3355 首先顯示了時間,然後可以看到數據傳輸方向,從C++->newlisp程序。還可以看到應用層傳輸的字節數目是4. 最後可以看到0100 3355 就是發出來的4個字節。 其他很多字節應該是TCP協議自身需要的數據。
Copyright © Linux教程網 All Rights Reserved