


Directory of this article:
##1.1 tcpdump options
1.2 tcpdump expression
##1.3 tcpdump example
tcpdump uses the command line to filter and capture interface data packets, and its rich features are reflected in flexible expressions.Tcpdump without any options will capture the first network interface by default, and packet capture will only stop when the tcpdump process is terminated.
For example:
shell> tcpdump -nn -i eth0 icmp
1.1 tcpdump options
Its command format is:
tcpdump [ -DenNqvX ] [ -c count ] [ -F ] [ -i interface ] [ -r -s snaplen ] [ - 注意,是最终要获取这么多个包。例如,指定若未指定该选项,将从系统接口列表中搜寻编号最小的已配置好的接口(不包括loopback接口,要抓取loopback接口使用tcpdump -i lo), :一旦找到第一个符合条件的接口,搜寻马上结束。可以使用-n:对地址以数字方式显式,否则显式为主机名,也就是说--N:不打印出host的域名部分。例如tcpdump将会打印而不是-P:指定要抓取的包是流入还是流出的包。可以给定的值为、和,默认为-s len:设置tcpdump的数据包抓取长度为len,如果不设置默认将会是65535字节。对于要抓取的数据包较大时,长度设置不够可能会产生包截断,若出现包截断, :输出行中会出现-----vv:产生比---:将抓包数据输出到文件中而不是标准输出。可以同时配合选项使得输出文件每time秒就自动切换到另一个文件。可通过-r:从给定的数据包文件中读取数据。使用表示从标准输入中读取。So commonly used options Just these:
- tcpdump -D
- ##tcpdump -c num -i int -nn -XX -vvv
1.2 tcpdump expression
A basic expression unit format is "proto dir type ID"
In addition to using expression units composed of modifiers and IDs, there are also keywords Expression units: gateway, broadcast, less, greater and arithmetic expressions.
Expression units can be connected using the operators "and / && / or / || / not / !"
to form complex conditional expressions. For example, "host foo and not port ftp and not port ftp-data", this means that the filtered data packets must meet the requirements of "packets with host foo and port not ftp (port 21) and ftp-data (port 20)", commonly used ports The corresponding relationship with the name can be found in the /etc/service file in the Linux system.In addition, the same modifiers can be omitted. For example, "tcp dst port ftp or ftp-data or domain" has the same meaning as "tcp dst port ftp or tcp dst port ftp-data or tcp dst port domain". All indicate that the protocol of the packet is tcp and the destination port is ftp or ftp-data or domain (port 53).
Using brackets "()" can change the priority of an expression, but it should be noted that the brackets will be interpreted by the shell, so the backslash "\" should be used to escape them to "\(\)". When needed, it also needs to be enclosed in quotation marks.1.3 tcpdump example
(1).Default startup
tcpdump
(2). Monitor the data packets of the specified network interface
tcpdump -i eth1
(3). Monitor the data packets of the specified host, such as all data packets entering or leaving longshuai
tcpdump host longshuai
tcpdump host helios and \( hot or ace \)
tcpdump ip host ace and not helios
(6).截获主机hostname发送的所有数据
tcpdump src host hostname
(7).监视所有发送到主机hostname的数据包
tcpdump dst host hostname
(8).监视指定主机和端口的数据包
tcpdump tcp port 22 and host hostname
(9).对本机的udp 123端口进行监视(123为ntp的服务端口)
tcpdump udp port 123
(10).监视指定网络的数据包,如本机与192.168网段通信的数据包,"-c 10"表示只抓取10个包
tcpdump -c 10 net 192.168
(11).打印所有通过网关snup的ftp数据包(注意,表达式被单引号括起来了,这可以防止shell对其中的括号进行错误解析)
shell> tcpdump 'gateway snup and (port ftp or ftp-data)'
(12).抓取ping包
[root@server2 ~]# tcpdump -c 5 -nn -i eth0 icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes12:11:23.273638 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16422, seq 10, length 6412:11:23.273666 IP 192.168.100.62 > 192.168.100.70: ICMP echo reply, id 16422, seq 10, length 6412:11:24.356915 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16422, seq 11, length 6412:11:24.356936 IP 192.168.100.62 > 192.168.100.70: ICMP echo reply, id 16422, seq 11, length 6412:11:25.440887 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16422, seq 12, length 645 packets captured6 packets received by filter0 packets dropped by kernel
如果明确要抓取主机为192.168.100.70对本机的ping,则使用and操作符。
[root@server2 ~]# tcpdump -c 5 -nn -i eth0 icmp and src 192.168.100.62tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes12:09:29.957132 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16166, seq 1, length 6412:09:31.041035 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16166, seq 2, length 6412:09:32.124562 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16166, seq 3, length 6412:09:33.208514 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16166, seq 4, length 6412:09:34.292222 IP 192.168.100.70 > 192.168.100.62: ICMP echo request, id 16166, seq 5, length 645 packets captured5 packets received by filter0 packets dropped by kernel
注意不能直接写icmp src 192.168.100.70,因为icmp协议不支持直接应用host这个type。
(13).抓取到本机22端口包
[root@server2 ~]# tcpdump -c 10 -nn -i eth0 tcp dst port 22 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes12:06:57.574293 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 535528834, win 2053, length 012:06:57.629125 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 193, win 2052, length 012:06:57.684688 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 385, win 2051, length 012:06:57.738977 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 577, win 2050, length 012:06:57.794305 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 769, win 2050, length 012:06:57.848720 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 961, win 2049, length 012:06:57.904057 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 1153, win 2048, length 012:06:57.958477 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 1345, win 2047, length 012:06:58.014338 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 1537, win 2053, length 012:06:58.069361 IP 192.168.100.1.5788 > 192.168.100.62.22: Flags [.], ack 1729, win 2052, length 010 packets captured10 packets received by filter0 packets dropped by kernel
(14).解析包数据
[root@server2 ~]# tcpdump -c 2 -q -XX -vvv -nn -i eth0 tcp dst port 22tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes12:15:54.788812 IP (tos 0x0, ttl 64, id 19303, offset 0, flags [DF], proto TCP (6), length 40)192.168.100.1.5788 > 192.168.100.62.22: tcp 00x0000: 000c 2908 9234 0050 56c0 0008 0800 4500 ..)..4.PV.....E.0x0010: 0028 4b67 4000 4006 a5d8 c0a8 6401 c0a8 .(Kg@.@.....d...0x0020: 643e 169c 0016 2426 5fd6 1fec 2b62 5010 d>....$&_...+bP.0x0030: 0803 7844 0000 0000 0000 0000 ..xD........12:15:54.842641 IP (tos 0x0, ttl 64, id 19304, offset 0, flags [DF], proto TCP (6), length 40)192.168.100.1.5788 > 192.168.100.62.22: tcp 00x0000: 000c 2908 9234 0050 56c0 0008 0800 4500 ..)..4.PV.....E.0x0010: 0028 4b68 4000 4006 a5d7 c0a8 6401 c0a8 .(Kh@.@.....d...0x0020: 643e 169c 0016 2426 5fd6 1fec 2d62 5010 d>....$&_...-bP.0x0030: 0801 7646 0000 0000 0000 0000 ..vF........2 packets captured2 packets received by filter0 packets dropped by kernel
总的来说,tcpdump对基本的数据包抓取方法还是较简单的。只要掌握有限的几个选项(-nn -XX -vvv -i -c -q),再组合表达式即可。
姊妹篇:网络扫描工具nmap
回到系列文章大纲:
转载请注明出处:
The above is the detailed content of Instructions for using the packet capture tool tcpdump. For more information, please follow other related articles on the PHP Chinese website!

JSP注释的分类及用法解析JSP注释分为两种:单行注释:以结尾,只能注释单行代码。多行注释:以/*开头,以*/结尾,可以注释多行代码。单行注释示例多行注释示例/**这是一段多行注释*可以注释多行代码*/JSP注释的用法JSP注释可以用来注释JSP代码,使其更易于阅

c语言exit函数怎么用,需要具体代码示例在C语言中,我们常常需要在程序中提前终止程序的执行,或者在某个特定的条件下退出程序。C语言提供了exit()函数来实现这个功能。本文将介绍exit()函数的用法,并提供相应的代码示例。exit()函数是C语言中的标准库函数,它包含在头文件中。它的作用是终止程序的执行,并且可以带一个整型

Python函数介绍:isinstance函数的用法和示例Python是一门功能强大的编程语言,提供了许多内置函数,使得编程变得更加方便和高效。其中一个非常有用的内置函数是isinstance()函数。本文将介绍isinstance函数的用法和示例,并提供具体的代码示例。isinstance()函数用于判断一个对象是否是指定的类或类型的实例。该函数的语法如下

Python函数介绍:abs函数的用法和示例一、abs函数的用法介绍在Python中,abs函数是一个内置函数,用于计算给定数值的绝对值。它可以接受一个数字参数,并返回该数字的绝对值。abs函数的基本语法如下:abs(x)其中,x是要计算绝对值的数值参数,可以是整数或浮点数。二、abs函数的示例下面我们将通过一些具体的示例来展示abs函数的用法:示例1:计算

Tcpdump是一款功能强大的网络分析工具,主要用于Linux系统和macOS中的网络流量分析。网络管理员可以通过tcpdump进行网络流量的捕获和分析,从而进行网络嗅探和监控TCP/IP数据包。它依赖于一个名为"libpcap"的库来有效地捕获网络流量。除了帮助网络管理员识别网络问题和解决故障外,tcpdump还有助于定期监测网络活动并检查网络安全性。捕获到的数据会被存储在一个名为"pcap"文件中,然后可以使用TCP/IP数据包分析工具(例如Wireshark)或其他命令行工具来进一步分析这

苹果快捷指令怎么用随着科技的不断发展,手机已经成为了人们生活中不可或缺的一部分。而在众多手机品牌中,苹果手机凭借其稳定的系统和强大的功能一直备受用户的喜爱。其中,苹果快捷指令这一功能更是让用户们的手机使用体验更加便捷和高效。苹果快捷指令是苹果公司为其iOS12及更高版本推出的一项功能,通过创建和执行自定义指令,帮助用户简化手机操作流程,以达到更高效的工作和

windows10常用快捷键可以为我们省去很多的时间,今天给大家介绍一些常用的快捷键用法,非常的方便快捷,下面一起来看看具体的使用方法吧。Win10快捷键用法介绍复制、粘贴和其他常规键盘快捷方式按此键执行此操作Ctrl+X剪切选定项Ctrl+C(或Ctrl+Insert)复制选定项Ctrl+V(或Shift+Insert)粘贴选定项Ctrl+Z撤消操作Alt+Tab在打开的应用之间切换Alt+F4关闭活动项,或者退出活动应用Windows徽标键+L锁定电脑Windows徽标键+D显示和隐藏桌面F

SQL中distinct用法详解在SQL数据库中,我们经常会遇到需要去除重复数据的情况。此时,我们可以使用distinct关键字,它能够帮助我们去除重复数据,使得查询结果更加清晰和准确。distinct的基本使用方法非常简单,只需要在select语句中使用distinct关键字即可。例如,以下是一个普通的select语句:SELECTcolumn_name


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
