抓取指定端口的数据包 并保存文件,用wireshark分析

tcpdump -Ans 4096 -i any port 8080 -w ../mpass.cap

 

抓取指定端口和指定ip的数据包 并保存文件,用wireshark分析

tcpdump -Ans 4096 -i any port 8080 and host 192.168.10.12 -w ../mpass.cap

-A 以 ascii 打印 (加上为了显示更多信息..?)

-n 不显示名称地址,显示主机ip 端口

-s 抓取的每个数据包的长度 (缺省  65535 bytes) 设置太大容易丢包

-i 表示指定的网卡, any是任意的意思

-w 指定文件保存路径

---------------------------------------------------------------------------------------

假设服务器的ip是 192.168.10.11

截获主机192.168.10.12发送的所有数据 [192.168.10.12 --> 192.168.10.11]  src 表示源(source)

tcpdump -i eth0 src host 192.168.10.12

监视所有送到主机192.168.10.12的数据包 [192.168.10.11 --> 192.168.10.12] dst表示目的地 (destination)

tcpdump -i eth0 dst host 192.168.10.12

 

eth0 代表第一块网卡  , 可以用ifconfig -a查看所有网卡

 

怎样保存文件读取数据包呢?

tcpdump -nnr test.pcap

选项 -nn 不把网络IP和端口号转换成名字,r(read)读取包。

可以添加 -tttt 选项使时间戳格式更加可读。

tcpdump -ttttnnr test.pcap

 

.pcap  .cap都是常见的数据包文件后缀