tcpdump示例

简介:

今天有需求要用tcpdump,给一个我使用的例子:

sudo /usr/sbin/tcpdump  dst 10.20.137.24 and tcp port 8080 -A -s0  -w nouse 

-A 表示只用ASCII码显示, 方便查看网页

-x 表示用16进制

-X 表示16进制和ASCII码同时显示 

-s0 表示不限制包的大小

-w 表示写入文件

 

参考了下面的文章,不胜感激。 

 

Let assume ,I wanna capture tcp packets that flow over eth1 port 6881. The dump file with be save as test.pcap.

 

tcpdump -w test.pcap -i eth1 tcp port 6881

Simple right? What if at the same time I am interested on getting packets on udp port 33210 and 33220?

tcpdump -w test.pcap -i eth1 tcp port 6881 or udp \( 33210 or 33220 \)

 

 

     ‘\’ is an escape symbol for ‘(’ and ‘)’. Logic OR implies PLUS (+). In plain text is I want to capture tcp packets flows over port 6881 plus udp ports 33210 and 33220.

Careful with ‘and’ in tcpdump filter expression, it means intersection. Thats why I put ‘or’ instead of and within udp port 33210 and 33220. The usage of ‘and’ in tcpdump will be illustrate later.

Ok, how about reading pcap that I saved previously?

tcpdump -nnr test.pcap

The -nn is to tell tcpdump not to resolve DNS on IP and Ports, where r is read.

Adding -tttt to makes the timestamp appears more readable format.

tcpdump -ttttnnr test.pcap

How about capture based on IP ?
You need to tell tcpdump which IP you are interested in? Destination IP? or Source IP ? Let say I wanna sniff on destination IP 10.168.28.22 tcp port 22, how should i write?

tcpdump -w test.pcap dst 10.168.28.22 and tcp port 22

So the ‘and’ makes the intersection of destination IP and port.

By default the sniff size of packets is 96 bytes, you somehow can overload that size by specified with -s.

tcpdump -w test.pcap -s 1550 dst 10.168.28.22 and tcp port 22

Some version of tcpdump allows you to define port range. You can as bellow for capturing packets based on a range of tcp port.

tcpdump tcp portrange 20-24

Bare in mind, the line above I didn’t specified -w which it won’t write to a file but i will just print the captured packets on the screen.

相关文章
|
Web App开发 安全 网络协议
Tcpdump命令的使用与示例——linux下的网络分析
顾名思义,TcpDump可以将网络中传送的数据包的“头”完全截获下来提供分析。它支持针对网络层、协议、主机、网络或端口的过滤,并提供and、or、not等逻辑语句来帮助你去掉无用的信息。
1040 0
|
2月前
|
运维 网络协议 安全
【Shell 命令集合 网络通讯 】Linux 网络抓包工具 tcpdump命令 使用指南
【Shell 命令集合 网络通讯 】Linux 网络抓包工具 tcpdump命令 使用指南
81 0
|
2月前
|
网络协议 Linux
Linux命令(120)之tcpdump
Linux命令(120)之tcpdump
46 0
|
8月前
|
Linux
linux下用tcpdump抓包
linux下用tcpdump抓包
|
2月前
|
数据采集 机器学习/深度学习 网络协议
Linux|操作系统|应该知道的网络抓包知识(主要是wireshark,tcpdump)
Linux|操作系统|应该知道的网络抓包知识(主要是wireshark,tcpdump)
85 0
|
机器学习/深度学习 网络协议 Linux
Linux网络管理之tcpdump命令 – 监听网络流量
tcpdump命令是一款sniffer工具,是linux上的抓包工具,嗅探器;它可以打印出所有经过网络接口的数据包的头信息。
657 0
Linux网络管理之tcpdump命令 – 监听网络流量
|
监控 网络协议 算法
Linux tcpdump命令详解(一)
Linux tcpdump命令详解(一)
351 0
|
机器学习/深度学习 运维 网络协议
Linux tcpdump,我的个人使用实例
Linux tcpdump,我的个人使用实例
196 0
|
Linux
Linux tcpdump命令详解(三)
Linux tcpdump命令详解(三)
283 0