詳解Linux系統(tǒng)中字符串搜索命令ngrep的用法

ngrep 是grep的網(wǎng)絡(luò)版,他力求更多的grep特征,用于搜尋指定的數(shù)據(jù)包。由于安裝ngrep需用到ibpcap庫(kù), 所以支持大量的操作系統(tǒng)和網(wǎng)絡(luò)協(xié)議,能識(shí)別TCP、UDP和ICMP包。
安裝ngrep
下載地址
git clone git://git.code.sf.net/p/ngrep/code ngrep-code
進(jìn)入目錄
cd ngrep-code
./configure --with-pcap-includes=/usr/local/include/pcap
make
make install
選項(xiàng)
-h is help/usage
-V is version information
-q is be quiet (don't print packet reception hash marks)靜默模式,如果沒(méi)有此開(kāi)關(guān),未匹配的數(shù)據(jù)包都以“#”顯示
-e is show empty packets 顯示空數(shù)據(jù)包
-i is ignore case 忽略大小寫(xiě)
-v is invert match 反轉(zhuǎn)匹配
-R is don't do privilege revocation logic
-x is print in alternate hexdump format 以16進(jìn)制格式顯示
-X is interpret match expression as hexadecimal 以16進(jìn)制格式匹配
-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在每個(gè)匹配的包之前顯示時(shí)間戳
-T is print delta timestamp every time a packet is matched顯示上一個(gè)匹配的數(shù)據(jù)包之間的時(shí)間間隔
-M is don't do multi-line match (do single-line match instead)僅進(jìn)行單行匹配
-I is read packet stream from pcap format file pcap_dump 從文件中讀取數(shù)據(jù)進(jìn)行匹配
-O is dump matched packets in pcap format to pcap_dump 將匹配的數(shù)據(jù)保存到文件
-n is look at only num packets 僅捕獲指定數(shù)目的數(shù)據(jù)包進(jìn)行查看
-A is dump num packets after a match匹配到數(shù)據(jù)包后Dump隨后的指定數(shù)目的數(shù)據(jù)包
-s is set the bpf caplen
-S is set the limitlen on matched packets
-W is set the dump format (normal, byline, single, none) 設(shè)置顯示格式byline將解析包中的換行符
-c is force the column width to the specified size 強(qiáng)制顯示列的寬度
-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定義的子協(xié)議號(hào)
-d is use specified device (index) instead of the pcap default
應(yīng)用舉例:
捕獲所有post請(qǐng)求(加個(gè)-W byline 參數(shù)后,將解析包中的換行符):
ranger@ranger:~$ sudo ngrep -q -W byline "(POST).*"
interface: eth0 (192.168.122.0/255.255.254.0)
match: (POST).*
T 192.168.122.74:46048 -> 140.207.228.58:80 [A]
POST /Hotel/OTA_HotelSearch.asmx?wsdl HTTP/1.1.
Content-Type: text/xml; charset=UTF-8.
SOAPAction: http://ctrip.com/Request.
Accept-Encoding: gzip, deflate.
Content-Length: 1330.
Accept: */*.
Accept-Language: zh-cn.
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0).
UA-CPU: x86.
Accept-Encoding: gzip, deflate.
Connection: close.
Host: openapi.ctrip.com.
.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Request xmlns="http://ctrip.com/"> <requestXML><Request>
<Header AllianceID="***" SID="***" TimeStamp="1393554304685" RequestType="OTA_HotelSearch" Signature="B166CDF5422A6DA5BA81A08036E938E7"/>
<HotelRequest>
<RequestBody xmlns:ns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ns:OTA_HotelSearchRQ Version="1.0" PrimaryLangID="zh"
xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelSearchRQ.xsd"
相關(guān)文章
- 命令提示符對(duì)我們操作電腦帶來(lái)了很多便利,那么我們?cè)撊绾未蜷_(kāi)“命令提示符”呢?下面小編給大家介紹下win10打開(kāi)命令提示符的幾種方法,一起看看吧2016-10-08
Win10系統(tǒng)中CMD命令提示符新增了哪些功能?
Win10系統(tǒng)中CMD命令提示符新增了哪些功能?win10系統(tǒng)中的cmd命令提示符增加了四個(gè)新的功能,下面我們就來(lái)看看這四個(gè)新功能的使用方法,需要的朋友可以參考下2016-09-26- 命令提示符是 Windows 中必不可少的一個(gè)系統(tǒng)管理的強(qiáng)有力工具,用戶可以使用各種命令實(shí)現(xiàn)一些圖形界面難以企及的管理方式。接下來(lái)通過(guò)本文給大家介紹Win10系統(tǒng)最全的命令提2016-08-22
- 這篇文章主要為大家詳細(xì)介紹了win10系統(tǒng)設(shè)置命令提示符窗口顏色的具體方法,感興趣的小伙伴們可以參考一下2016-10-20
- win10系統(tǒng)中命令提示符閃退該怎么解決?win10系統(tǒng)中打開(kāi)命令提示符,無(wú)論是管理員權(quán)限還是普通用戶,都閃退,這是怎么回事?下面我們就來(lái)看看這個(gè)問(wèn)題的解決辦法,需要的朋2016-08-04
Win10系統(tǒng)中使用Win8系統(tǒng)命令提示符的設(shè)置方法圖文教程
很多用戶都已升級(jí)安裝了最新的win10系統(tǒng),而有些用戶卻像依然想使用Win8系統(tǒng)命令提示符,那么在Win10系統(tǒng)中如何設(shè)置使用Win8系統(tǒng)命令提示符呢?本文將提供設(shè)置方法供大家了2016-05-06win10系統(tǒng)中怎么讓CMD命令提示符復(fù)制粘貼更快捷?
win10系統(tǒng)中怎么讓CMD命令提示符復(fù)制粘貼更快捷?在MD命令提示符窗口中卻無(wú)法使用左鍵拖動(dòng)選擇需要復(fù)制的內(nèi)容,怎么才能更快捷的操作復(fù)制粘貼動(dòng)作呢?請(qǐng)看下文詳細(xì)介紹2016-04-24Win7系統(tǒng)如何設(shè)置CMD命令提示符窗口的背景顏色
最近總是有朋友問(wèn)我,win7系統(tǒng)如何設(shè)置cmd命令提示符窗口的背景顏色,下面小編把解決辦法分享到腳本之家平臺(tái)供大家參考2016-04-19- win10系統(tǒng)中打開(kāi)命令提示符的方法很多,之前我們也介紹了,今天我們來(lái)匯總一下,發(fā)現(xiàn)一共有七種不同的打開(kāi)方法,下面我們來(lái)看看Win10管理員命令提示符窗口的七種打開(kāi)方法匯2016-03-23
Win7系統(tǒng)CMD命令提示符輸入中文變亂碼的解決方法
Win7系統(tǒng)下經(jīng)常使用CMD命令提示符,此功能強(qiáng)大,可以進(jìn)行很多操作,不過(guò)有時(shí)發(fā)現(xiàn)Win7旗艦版系統(tǒng)在CMD命令提示符不能輸入文字,輸入的中文字都變成亂碼,這是怎么回呢?本文2016-02-29