[20200227]使用tcpdump or and ()語法問題.txt
[20200227]使用tcpdump or and ()語法問題.txt
--//這幾天使用tcpdump調式網路,遇到一點點問題,做一個記錄。
# tcpdump -nnn -i eth0 port 15210 or host 192.168.100.40 and not port 514
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
16:09:22.699011 IP 192.168.100.40.1521 > 192.168.100.78.65202: . ack 3859187154 win 154
16:09:22.699164 IP 192.168.100.78.15210 > 192.168.98.6.65202: . ack 3859187154 win 154
16:09:22.699372 IP 192.168.98.6.65202 > 192.168.100.78.15210: . ack 1 win 16288
16:09:22.699393 IP 192.168.100.78.65202 > 192.168.100.40.1521: . ack 1 win 16288
--//實際上上面的過濾條件並不是我實際需要的。我實際想表達的是:
( port 15210 or host 192.168.100.40 ) and not port 514
--//只不過當時的過濾輸出已經滿足解決問題需要,我當時沒有過多探究。
# tcpdump -nnn -i eth0 (port 15210 or host 192.168.100.40 ) and not port 514
-bash: syntax error near unexpected token `('
--//不能使用()嗎?實際上bash shell上使用(),要加入\轉義以下。
# tcpdump -nnn -i eth0 \( port 15210 or host 192.168.100.40 \) and not port 514
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
16:12:48.152788 IP 192.168.98.6.65202 > 192.168.100.78.15210: P 3859187154:3859187673(519) ack 425548478 win 16288
16:12:48.152933 IP 192.168.100.78.65202 > 192.168.100.40.1521: P 3859187154:3859187673(519) ack 425548478 win 16288
16:12:48.154236 IP 192.168.100.40.1521 > 192.168.100.78.65202: P 1:737(736) ack 519 win 154
16:12:48.154277 IP 192.168.100.78.15210 > 192.168.98.6.65202: P 1:737(736) ack 519 win 154
--//實際上看tcpdump 手冊,可以發現例子,還可以使用單引號解決這個問題:
# tcpdump -nnn -i eth0 '(port 15210 or host 192.168.100.40 ) and not port 514'
EXAMPLES
To print all packets arriving at or departing from sundown:
tcpdump host sundown
To print traffic between helios and either hot or ace:
tcpdump host helios and \( hot or ace \)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To print all IP packets between ace and any host except helios:
tcpdump ip host ace and not helios
To print all traffic between local hosts and hosts at Berkeley:
tcpdump net ucb-ether
To print all ftp traffic through internet gateway snup: (note that the expression is quoted to prevent the shell
from (mis-)interpreting the parentheses):
tcpdump 'gateway snup and (port ftp or ftp-data)'
To print traffic neither sourced from nor destined for local hosts (if you gateway to one other net, this stuff
should never make it onto your local net).
tcpdump ip and not net localnet
To print the start and end packets (the SYN and FIN packets) of each TCP conversation that involves a non-local host.
tcpdump 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet'
To print all IPv4 HTTP packets to and from port 80, i.e. print only packets that contain data, not, for example,
SYN and FIN packets and ACK-only packets. (IPv6 is left as an exercise for the reader.)
tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
To print IP packets longer than 576 bytes sent through gateway snup:
tcpdump 'gateway snup and ip[2:2] > 576'
To print IP broadcast or multicast packets that were not sent via Ethernet broadcast or multicast:
tcpdump 'ether[0] & 1 = 0 and ip[16] >= 224'
To print all ICMP packets that are not echo requests/replies (i.e., not ping packets):
tcpdump 'icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply'
--//tcpdump 功能很強大,後面這些例子基本沒有使用過。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2677501/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20160809]exp語法問題.txt
- [20160803]exp/imp語法問題.txt
- 語法問題
- goroutine 語法問題Go
- 使用tcpdump解決應用不能執行問題TCP
- 語法上的小問題
- tcpdump使用TCP
- latex 語法塊中字型加粗問題、換行問題
- Tcpdump使用示例TCP
- Tcpdump的使用TCP
- openJPA 遭遇PG 之 like 語法問題
- [20160910]sqlldr使用問題.txtSQL
- TcpDump使用手冊TCP
- JS語法: 由++[[]][+[]]+[+[]] = 10 ?引發的問題JS
- mysql8.0 部分sql語法報錯問題MySql
- [20181101]使用putty無法登入redhat 7.X版本問題.txtRedhat
- tcpdump命令簡單使用TCP
- 解決無法使用VI的問題
- JavaScript 新語法 「雙問號語法」與「可選鏈語法」JavaScript
- postgresql copy UNICODE txt 問題。SQLUnicode
- [20160113]sqlplus使用問題.txtSQL
- C語言常見使用問題2C語言
- JavaScript瀏覽器歷史的語法小問題JavaScript瀏覽器
- 關於debian系統下使用vi編輯語法不高亮的問題
- [20211221]分析sql語句遇到的問題.txtSQL
- [20130628]sql語句顯示不全的問題.txtSQL
- markdown 標題語法
- 抓取Android平臺資料包之tcpdump 工具的使用過程中出現的問題AndroidTCP
- [20160213]關於ansi語法.txt
- jsp無法使用bean的問題 等到解決問題為止!!!!JSBean
- 解決Vite-React專案中js使用jsx語法報錯的問題ViteReactJS
- 機器學習無法解決自然語言理解問題 - thegradient機器學習
- JavaScript語法裡一些難點問題彙總JavaScript
- [20150705]從AWR抽取有問題的sql語句.txtSQL
- CMakeLists.txt 語法介紹與例項演練
- [20230905]奇怪的語法.txt
- vsftp無法使用root登陸的問題FTP
- autohotkey qt程式中無法使用的問題QT