歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> tcpdump、nc網絡工具使用

tcpdump、nc網絡工具使用

日期:2017/2/28 13:45:15   编辑:Linux教程

tcpdump: 網絡嗅探器

nc:

nmap: 端口掃描

混雜模式(promisc)

C設置為監控,當A和B通信,C是無法探測到數據的,除非有交換機的權限,將全網端口的數據通信都發送副本到C的端口上。

此設置過程為鏡像端口

tcpdump

-i: interface指定網卡

-w file

-nn: 將ip解析為數字,第二個n:將端口顯示為數字

-X: hex and ASCII

-XX: 顯示鏈路層首部信息

-A: ASCII

-v: 詳細顯示

-vv: 更詳細顯示

-r file: 讀取文件進行解碼

expression:

關鍵字:

type: host, net, port, portrange

direction: src, dst, src or dst, src and dst

protocol: ether, ip, arp, tcp, udp, wlan

組合條件:

and

or

not

目標端口tcp協議80:

tcpdump -i eth0 tcp dst port 80 [-nn] # 其中第一個n表示將ip以數字格式顯示,第二個n表示將端口以數字格式顯示

源、目標端口為80:

tcpdump -i eth0 tcp port 80 [-nn]

抓取與[源|目標]主機為172.16.100.6之間的通信:

tcpdump -i eth0 -nn [src|dst] host 172.16.100.6

抓取源和目標相同的報文:

tcpdump -i eth0 -nn src and dst host 172.16.100.6

組合條件:

抓取兩台主機之間的通信:

tcpdump -i eth0 -nn host 172.16.100.6 and 172.16.100.77

更高的用法:

tcpdump -i eth0 -nn host 172.16.10.6 and \(172.16.200.73 or 172.16.100.77\)

還有tshark

還有

如果Linux安裝有圖形界面:

yum install wireshark-gnome -y

nc: 由nc提供

rpm -qf `which nc`

另一個實現:ncat,由nmap提供

nc可以用來兩台服務器之間傳輸數據:

接收端:

nc -l 2233 > /tmp/test

監聽在2233端口,並將收到的數據存放為/tmp/test文件

發送端:

nc 接收端IP port < /root/test

也可以自己監聽,發送文件:

nc -l 2234 < /tmp/test

接收端:

nc 發送端IP port > /tmp/test

既可以使用輸入重定向也可以使用輸出重定向

文件傳輸方案:監聽者為接收方

nc -l PORT > /path/to/somefile

nc IP PORT < /path/from/somefile

文件傳輸:監聽者為傳輸方

nc -l PORT < /path/from/somefile

nc IP PORT > /path/to/somefile

-p PORT : 指明連接監聽的服務器時使用的端口,如果不指明,則使用隨機端口

-s 指定本地使用哪個ip訪問

注意:

1、如果傳輸目錄的話,需要先將目錄歸檔或者壓縮後再傳輸

2、如果此時不使用重定向的話,可以做為兩端實時信息傳遞,只要不指定傳文件就不會斷開了

作為web客戶端:

-v 掃描時詳細格式輸出

-w 等待時間

-z 1-1024 掃描端口

例如:nc -w 1 IP -z 1-1024 等待1s,掃描端口范圍為1-1024

nmap命令使用說明。

Copyright © Linux教程網 All Rights Reserved