計算機網絡實用工具之tcpdump

簡介

tcpdump是一個運行在命令行下的數據包分析器。能夠獲取到該計算機發送或接收的TCP/IP和其他數據包。

tcpdump 適用于大多數的類Unix操作系統,包括Linux、Solaris、BSD、Mac OS X、HP-UX和AIX 等等。在這些系統中,tcpdump 需要使用libpcap這個捕捉數據的庫。其在Windows下的版本稱為WinDump,它需要WinPcap驅動,相當于在Linux平臺下的libpcap。

可以用于打印在網絡接口上收發的數據包,過濾與特定表達式匹配的數據包;可以使用此工具來跟蹤網絡問題、檢測攻擊或監視網絡活動。

官網

Home | TCPDUMP & LIBPCAP

安裝

# tcpdump依賴于libpcap# ubuntu 22.04
# 查看libpcap
ubuntu~$ dpkg -l |grep libpcap
ii  libpcap0.8:amd64                       1.10.1-4build1                          amd64        system interface for user-level packet capture# 安裝tcpdump
ubuntu~$ sudo apt install tcpdump# centos 7
# 查看libpcap
[root@centos7 ~]# rpm -qa libpcap
libpcap-1.5.3-13.el7_9.x86_64# 安裝tcpdump
[root@centos7 ~]# sudo yum install tcpdump

使用幫助

[root@centos7 ~]# tcpdump -h
tcpdump version 4.99.1
libpcap version 1.10.1 (with TPACKET_V3)
OpenSSL 3.0.2 15 Mar 2022
Usage: tcpdump [-AbdDefhHIJKlLnNOpqStuUvxX#] [ -B size ] [ -c count ] [--count][ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ][ -i interface ] [ --immediate-mode ] [ -j tstamptype ][ -M secret ] [ --number ] [ --print ] [ -Q in|out|inout ][ -r file ] [ -s snaplen ] [ -T type ] [ --version ][ -V file ] [ -w file ] [ -W filecount ] [ -y datalinktype ][ --time-stamp-precision precision ] [ --micro ] [ --nano ][ -z postrotate-command ] [ -Z user ] [ expression ]

使用示例

運行 tcpdump 的通用格式是: tcpdump <options> <expression>

options

# 查看網卡tcpdump -D或tcpdump --list-interfaces
root@ubuntu:~# tcpdump -D
1.ens33 [Up, Running]
2.lo [Up, Running, Loopback]
3.any (Pseudo-device that captures on all interfaces) [Up, Running]
4.docker0 [Up]
5.bluetooth-monitor (Bluetooth Linux Monitor) [none]
6.nflog (Linux netfilter log (NFLOG) interface) [none]
7.nfqueue (Linux netfilter queue (NFQUEUE) interface) [none]
8.bluetooth0 (Bluetooth adapter number 0) [none]
root@ubuntu:~# 
root@ubuntu:~# tcpdump --list-interfaces
1.ens33 [Up, Running]
2.lo [Up, Running, Loopback]
3.any (Pseudo-device that captures on all interfaces) [Up, Running]
4.docker0 [Up]
5.bluetooth-monitor (Bluetooth Linux Monitor) [none]
6.nflog (Linux netfilter log (NFLOG) interface) [none]
7.nfqueue (Linux netfilter queue (NFQUEUE) interface) [none]
8.bluetooth0 (Bluetooth adapter number 0) [none]# 指定接口
# 所有接口
root@ubuntu:~# tcpdump -i any# ens33接口-i interface或--interface=interface
root@ubuntu:~# tcpdump -i ens33
root@ubuntu:~# tcpdump --interface=ens33# 將icmp數據包保存到icmp.pcap文件,參數-w,使用-w時,數據包不會顯示在終端上。
root@ubuntu:~# tcpdump --interface=ens33 -w icmp.pcap icmp# 限制文件大小,-C參數,必須和-w參數一起使用
# 抓取的數據包保存到test.pcap文件中,大小達到2M時生成新的文件test.pcap1,數字遞增
root@ubuntu:~# tcpdump -w test.pcap -C 2# 從文件中讀取數據
root@ubuntu:/tmp# tcpdump -r test.pcap# -v參數,獲取更多信息,-c 1意思是獲取到1個數據包后停止,-n 不要將地址轉換為名稱
root@ubuntu:/tmp# tcpdump -n -c 1 icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
14:18:26.384013 IP 192.168.21.128 > 183.2.172.42: ICMP echo request, id 5, seq 1, length 64
1 packet captured
2 packets received by filter
0 packets dropped by kernel
root@ubuntu:/tmp# 
root@ubuntu:/tmp# tcpdump -v -n -c 1 icmp
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
14:19:01.320676 IP (tos 0x0, ttl 64, id 21682, offset 0, flags [DF], proto ICMP (1), length 84)192.168.21.128 > 183.2.172.185: ICMP echo request, id 6, seq 1, length 64
1 packet captured
2 packets received by filter
0 packets dropped by kernel# 如果您還想以 ASCII 格式打印每個數據包的內容,則可以使用該 -A選項。例如,這將顯示 HTTP 請求和響應的內容。
root@ubuntu:/tmp# tcpdump -A -n src port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
14:24:47.351778 IP 183.2.172.42.80 > 192.168.21.128.44002: Flags [S.], seq 2034896310, ack 4106329319, win 64240, options [mss 1460], length 0
E..,
......X...*.....P..yJ......`.............
14:24:47.352217 IP 183.2.172.42.80 > 192.168.21.128.44002: Flags [.], ack 78, win 64240, length 0
E..(
......[...*.....P..yJ.....4P....c........
14:24:47.378366 IP 183.2.172.42.80 > 192.168.21.128.44002: Flags [.], seq 1:1461, ack 78, win 64240, length 1460: HTTP: HTTP/1.1 200 OK
E............*.....P..yJ.....4P.......HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 2381
Content-Type: text/html
Date: Wed, 22 Nov 2023 14:24:47 GMT
Etag: "588604dc-94d"
Last-Modified: Mon, 23 Jan 2017 13:27:56 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>...........................</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=............ class="bg s_btn"></span> 
14:24:47.378452 IP 183.2.172.42.80 > 192.168.21.128.44002: Flags [P.], seq 1461:2782, ack 78, win 64240, length 1321: HTTP
E..Q
!.....0...*.....P..yJ.k...4P...Q...</form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>......</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>......</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>......</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>......</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>......</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">......</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">............</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>............</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>.....................</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>............</a>&nbsp;...ICP...030173...&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>14:24:47.378907 IP 183.2.172.42.80 > 192.168.21.128.44002: Flags [.], ack 79, win 64239, length 0
E..(
".....X...*.....P..yJ.....5P.............
14:24:47.403420 IP 183.2.172.42.80 > 192.168.21.128.44002: Flags [FP.], seq 2782, ack 79, win 64239, length 0
E..(
#.....W...*.....P..yJ.....5P....}........# 顯示數據鏈路層地址使用-e參數
root@ubuntu:/tmp# tcpdump -e -c 2 -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
14:26:54.254562 00:0c:29:2b:39:27 > 00:50:56:c0:00:08, ethertype IPv4 (0x0800), length 242: 192.168.21.128.22 > 192.168.21.1.49523: Flags [P.], seq 117054726:117054914, ack 2091745178, win 501, length 188
14:26:54.254829 00:0c:29:2b:39:27 > 00:50:56:c0:00:08, ethertype IPv4 (0x0800), length 298: 192.168.21.128.22 > 192.168.21.1.49523: Flags [P.], seq 188:432, ack 1, win 501, length 244
2 packets captured
3 packets received by filter
0 packets dropped by kernel# 禁用混雜模式-p或--no-promiscuous-mode

expression

# type
host for an individual host (e.g. host 192.168.1.1)
net for network (e.g. net 192.168.0.0/24),
port for a port number (e.g. port 22)
portrange for a ranges of ports (e.g. portrange 1000-2000)
If no type is specified, host is assumed.# dir
src - source only
dst - destination only
src or dst - either side of the connection may match
src and dst both source and destination should match the specified identifier
If no direction is specified, src or dst is assumed.# proto
This qualifier lets you target only a specific protocol. Protocols that you may wish to specify include:ether (Ethernet)
wlan (Wireless Lan)
ip (Internet Protocol v4)
ip6 (Internet Protocol v6)
arp (Address Resolution Protocol)
rarp (Reverse - ARP)
tcp (Transmission Control Protocol)
udp (User Datagram Protocol)# Combining filter expressions with and, or, not
not
Can also be written as ! - select only traffic which does not match the expression which follows.
tcpdump not tcp # match only traffic which doesn't use the TCP protocoland
Can also be written as && - select traffic which matches both the preceding expression and the following expression.
tcpdump icmp and host google.dnsor
Can also be written as || - select traffic which matches the preceding expression or the following expression.# 示例:
# 以下兩句是等效的
tcpdump tcp dst port 80 or tcp dst port 443
tcpdump tcp dst port 80 or 443# 可以使用括號()進一步定義邏輯:
tcpdump host athena and (port 80 or 443)# 協議過濾
tcpdump ip and tcp# 基于IP地址的過濾
tcpdump src host 192.168.1.1 and dst host 192.168.1.2tcpdump net 192.168.1    # filter for all traffic from the 192.168.1.0/24 subnet(192.168對應于192.168.0.0/16)# 端口過濾器
tcpdump src portrange 10000-20000 and dst port 443# 數據包長度
tcpdump ip host 192.168.1.1 and less 100
tcpdump icmp greater 50

種草

本文為"計算機網絡實用工具系列"的內容之一,會持續更新其它相關博文

我的博文內容主要針對“計算機網絡”、“安全”、“運維”和“云計算”方向,感興趣朋友的請關注我,我將不定期發布新的博文并不斷改進已發布博文。

后期依據大家對博文的評論,點贊及關注情況,針對大家感興趣的內容我也會錄制視頻并整理出成套的學習資料免費分享給大家,期待能和大家一起交流學習。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/162197.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/162197.shtml
英文地址,請注明出處:http://en.pswp.cn/news/162197.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Altium Designer學習筆記9

忽視了一個最大的問題&#xff0c;就是元器件的封裝&#xff0c;不應該是根據AD系統的封裝走&#xff0c;而應該是根據立創商城上的規格書&#xff0c;確認每個封裝的大小&#xff0c;畫出封裝圖&#xff0c;然后才是布局和走線。 1、確認電容的封裝采用0805&#xff0c;貼片電…

【css】Google第三方登錄按鈕樣式修改

文章目錄 場景前置準備修改樣式官方屬性修改樣式CSS修改樣式按鈕的高度height和border-radiusLogo和文字布局 場景 需要用到谷歌的第三方登錄&#xff0c;登錄按鈕有自己的樣式。根據官方文檔&#xff1a;概覽 | Authentication | Google for Developers&#xff0c;提供兩種第…

局域網協議:地址解析協議(ARP,Address Resolution Protocol)

地址解析協議&#xff08;ARP&#xff0c;Address Resolution Protocol&#xff09;是一種用于在IP網絡中將IP地址映射到物理MAC地址的協議。在IP網絡中&#xff0c;IP是用于尋址&#xff0c;真正將數據包從一個設備發送到另外一個設備&#xff0c;用于通信的是物理MAC地址。 …

40、Flink 的Apache Kafka connector(kafka sink的介紹及使用示例)-2

Flink 系列文章 1、Flink 部署、概念介紹、source、transformation、sink使用示例、四大基石介紹和示例等系列綜合文章鏈接 13、Flink 的table api與sql的基本概念、通用api介紹及入門示例 14、Flink 的table api與sql之數據類型: 內置數據類型以及它們的屬性 15、Flink 的ta…

geemap學習筆記012:如何搜索Earth Engine Python腳本

前言 本節主要是介紹如何查詢Earth Engine中已經集成好的Python腳本案例。 1 導入庫 !pip install geemap #安裝geemap庫 import ee import geemap2 搜索Earth Engine Python腳本 很簡單&#xff0c;只需要一行代碼。 geemap.ee_search()使用方法 后記 大家如果有問題需…

vue截取URL中的參數

url&#xff1a; http://localhost:81/login?redirect%2Findex&access_tokeneyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvdUV4dGVybmFsSWQiOiI0OTI2MjYzMTIxMDU1NDAxMTM4IiwiYXVkIjpbImVudGVycHJpc2VfbW9iaWxlX3Jlc291cmNlIiwiYmZmX2FwaV9yZXN 截取參數&#xff1a; let…

如何提高圖片轉excel的效果?(軟件選擇篇)

在日常的工作中&#xff0c;我們常常會遇到一些財務報表類的圖片需要轉換成可編輯的excel&#xff0c;但是&#xff0c;受各種條件的限制&#xff0c;常常只能通過手工錄入這種原始的方式來實現&#xff0c;隨著人工智能、深度學習以及網絡技術的發展&#xff0c;這種原始的錄入…

SpringBoot集成七牛云OSS詳細介紹

&#x1f4d1;前言 本文主要SpringBoot集成七牛云OSS詳細介紹的文章&#xff0c;如果有什么需要改進的地方還請大佬指出?? &#x1f3ac;作者簡介&#xff1a;大家好&#xff0c;我是青衿&#x1f947; ??博客首頁&#xff1a;CSDN主頁放風講故事 &#x1f304;每日一句&a…

【Java工具篇】Java反編譯工具Bytecode Viewer

&#x1f49d;&#x1f49d;&#x1f49d;歡迎來到我的博客&#xff0c;很高興能夠在這里和您見面&#xff01;希望您在這里可以感受到一份輕松愉快的氛圍&#xff0c;不僅可以獲得有趣的內容和知識&#xff0c;也可以暢所欲言、分享您的想法和見解。 推薦:kwan 的首頁,持續學…

【C++高階(四)】紅黑樹深度剖析--手撕紅黑樹!

&#x1f493;博主CSDN主頁:杭電碼農-NEO&#x1f493; ? ?專欄分類:C從入門到精通? ? &#x1f69a;代碼倉庫:NEO的學習日記&#x1f69a; ? &#x1f339;關注我&#x1faf5;帶你學習C ? &#x1f51d;&#x1f51d; 紅黑樹 1. 前言2. 紅黑樹的概念以及性質3. 紅黑…

計算機網絡之數據鏈路層

一、概述 1.1概述 物理層發出去的信號需要通過數據鏈路層才知道是否到達目的地&#xff1b;才知道比特流的分界線 鏈路(Link)&#xff1a;從一個結點到相鄰結點的一段物理線路&#xff0c;中間沒有任何其他交換結點數據鏈路(Data Link)&#xff1a;把實現通信協議的硬件和軟件…

電商API接口|電商數據接入|拼多多平臺根據商品ID查商品詳情SKU和商品價格參數

隨著科技的不斷進步&#xff0c;API開發領域也逐漸呈現出蓬勃發展的勢頭。今天我將向大家介紹API接口&#xff0c;電商API接口具備獨特的特點&#xff0c;使得數據獲取變得更加高效便捷。 快速獲取API數據——優化數據訪問速度 傳統的數據獲取方式可能需要經過多個中介環節&…

華大基因認知障礙基因檢測服務,助力認知障礙疾病防控

認知障礙是一種嚴重的神經系統疾病&#xff0c;對人類的腦健康產生了重大影響。據報告顯示&#xff0c;在我國65歲以上的人群中&#xff0c;存在輕度認知障礙的患者約為3,800萬&#xff0c;而中重度癡呆患者則約為1,500萬&#xff0c;患病人口數量龐大。這種疾病不僅會對患者的…

免費多域名SSL證書

顧名思義&#xff0c;免費多域名SSL證書就是一種能夠為多個域名或子域提供HTTPS安全保護的證書。這意味著&#xff0c;如果您有三個域名——例如example.com、example.cn和company.com&#xff0c;您可以使用一個免費的多域名SSL證書為所有這些域名提供安全保障&#xff0c;而無…

TransFusionNet:JetsonTX2下肝腫瘤和血管分割的語義和空間特征融合框架

TransFusionNet: Semantic and Spatial Features Fusion Framework for Liver Tumor and Vessel Segmentation Under JetsonTX2 TransFusionNet&#xff1a;JetsonTX2下肝腫瘤和血管分割的語義和空間特征融合框架背景貢獻實驗方法Transformer-Based Semantic Feature Extractio…

pyhton接口猜用戶登錄和密碼

import requests import base64 NUM 0 # 讀取 URL 文件內容并生成 URL 列表 with open("urlall.txt", r) as file:urls [url.strip() for url in file.readlines() if url.strip()]# 讀取密碼文件內容并生成密碼列表 with open("password.txt", r) as fil…

前端下載多個文件鏈接整合為壓縮包

前端下載多個文件鏈接整合為壓縮包 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</ti…

AI寫代碼 可以代替人工嗎?

近年AI技術非常火熱&#xff0c;有人就說&#xff0c;用AI寫代碼程序員不就都得下崗嗎&#xff1f;對此我的回答是否定的&#xff0c;因為AI雖然已經有了編寫代碼的能力&#xff0c;但它現在的水平大多還僅限于根據業務需求搭建框架&#xff0c;而具體的功能實現還尚且稚嫩&…

11.22 知識總結(cookie、 session相關知識點)

一、 Cookie和Session的發展史 一開始&#xff1a;只有一個頁面&#xff0c;沒有登錄功能&#xff0c;大家看到東西都一樣 新聞 時代發展&#xff0c;出現了需要登錄注冊的網站&#xff0c;要有一門技術存儲我們的登錄信息 京東、天貓 cookie 存儲形式&#xff1a;k:v鍵值對 …

【愚公系列】保姆級教程帶你實現HarmonyOS手語猜一猜元服務

&#x1f680;前言 最近HarmonyOS NEXT大火&#xff0c;這個純血鴻蒙吸引力了大家的關注。雖然現在還沒面向個人開發者開放&#xff0c;但我們可以基于最新的API9及開發工具來嘗試開發鴻蒙新的應用形態——元服務。來體驗下未來在HarmonyOS NEXT上實現的應用開發。 HarmonyOS…