当前位置: 首页 > 工具软件 > Ngrep > 使用案例 >

linux之网络分析利器ngrep

钱稳
2023-12-01

ngrep

Ngrep ( 网络grep )是一个简单但功能强大的网络数据包分析器。 它是一种应用于网络层的类似grep的工具 - 它匹配通过网络接口传递的流量。 它允许您指定扩展的常规或十六进制表达式,以匹配数据包的数据有效负载(传输数据中的实际信息或消息,但不包括自动生成的元数据)。

此工具适用于各种类型的协议,包括IPv4 / 6,TCP,UDP,ICMPv4 / 6,IGMP以及许多接口上的Raw。 它的运行方式与tcpdump数据包嗅探工具相同 。

安装

直接使用yum安装即可

yum install -y ngrep 

语法

usage: ngrep <-LhNXViwqpevxlDtTRM> <-IO pcap_dump> <-n num> <-d dev> <-A num>
<-s snaplen> <-S limitlen> <-W normal|byline|single|none> <-c cols>
<-P char> <-F file> <match expression> <bpf filter>

-h is help/usage
-V is version information
-q is be quiet (don't print packet reception hash marks)静默模式,如果没有此开关,未匹配的数据包都以“#”显示
-e is show empty packets 显示空数据包
-i is ignore case 忽略大小写
-v is invert match 反转匹配
-R is don't do privilege revocation logic
-x is print in alternate hexdump format 以16进制格式显示
-X is interpret match expression as hexadecimal 以16进制格式匹配
-w is word-regex (expression must match as a word) 整字匹配
-p is don't go into promiscuous mode 不使用混杂模式
-l is make stdout line buffered
-D is replay pcap_dumps with their recorded time intervals
-t is print timestamp every time a packet is matched在每个匹配的包之前显示时间戳
-T is print delta timestamp every time a packet is matched显示上一个匹配的数据包之间的时间间隔
-M is don't do multi-line match (do single-line match instead)仅进行单行匹配
-I is read packet stream from pcap format file pcap_dump 从文件中读取数据进行匹配
-O is dump matched packets in pcap format to pcap_dump 将匹配的数据保存到文件
-n is look at only num packets 仅捕获指定数目的数据包进行查看
-A is dump num packets after a match匹配到数据包后Dump随后的指定数目的数据包
-s is set the bpf caplen
-S is set the limitlen on matched packets
-W is set the dump format (normal, byline, single, none) 设置显示格式byline将解析包中的换行符
-c is force the column width to the specified size 强制显示列的宽度
-P is set the non-printable display char to what is specified
-F is read the bpf filter from the specified file 使用文件中定义的bpf(Berkeley Packet Filter)
-N is show sub protocol number 显示由IANA定义的子协议号
-d is use specified device (index) instead of the pcap default 使用哪个网卡,可以用-L选项查询,一般调试会使用 any 
-L is show the winpcap device list index 查询网卡接口

常用命令

监听端口25上的所有数据包

ngrep -d any port 25

监听端口25,匹配 user字符串

ngrep -d any user port 25

监听端口25,匹配user或者pass字符串

ngrep -d any 'user|pass' port 25

监听80端口,数据以行显示

ngrep -d any -Wbyline port 80

监听www.baidu.com匹配pass字符串

ngrep -d any -Wbyline 'pass' host www.baidu.com

未完待补充。。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 类似资料: