2013-02-08 74 views
2

我需要實現一個代碼,它能夠每秒向一定數量的目標發送ping數據包。問題是我想在1秒窗口內ping儘可能多的目的地。出於這個原因,我在想如果有一種方法將循環強加到nmap [我的意思是像循環nmap參數],以便套接字將只打開一次,並在循環ping結束時關閉,節省的方式比使用「觀看nmap」的方法!NMAP連續ping

回答

1

你可以通過產卵在命令行並行複式NMAP進程:

nmap [options for destination 0] > output0 & 

菌種許多這樣NMAP爲每個目的地的請求,同時保持outputX文件(OUTPUT0,輸出1,等等)的運行索引..當您的所有請求都完成後,您可以檢查每個輸出文件的內容

+0

如果所有實例都應該登錄到同一文件,請嘗試使用'>>'而不是'>'。 – sjas 2017-07-19 12:05:28

3

Nmap項目的一部分是Nping tool。它旨在完成您想要的功能,並且非常易於配置。下面是一個示例運行:

$ sudo nping --rate 4 --icmp 192.168.1.4/30 

Starting Nping 0.6.26SVN (http://nmap.org/nping) at 2013-02-08 11:53 CST 
SENT (0.0192s) ICMP 192.168.1.142 > 192.168.1.5 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (0.2692s) ICMP 192.168.1.142 > 192.168.1.6 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (0.5193s) ICMP 192.168.1.142 > 192.168.1.7 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (0.7695s) ICMP 192.168.1.142 > 192.168.1.4 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (1.0196s) ICMP 192.168.1.142 > 192.168.1.5 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (1.2701s) ICMP 192.168.1.142 > 192.168.1.5 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
RCVD (1.2707s) ICMP 192.168.1.5 > 192.168.1.142 Echo reply (type=0/code=0) ttl=64 id=34160 iplen=28 
SENT (1.5206s) ICMP 192.168.1.142 > 192.168.1.7 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (1.7708s) ICMP 192.168.1.142 > 192.168.1.4 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (2.0209s) ICMP 192.168.1.142 > 192.168.1.5 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (2.2712s) ICMP 192.168.1.142 > 192.168.1.5 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
RCVD (2.2717s) ICMP 192.168.1.5 > 192.168.1.142 Echo reply (type=0/code=0) ttl=64 id=34161 iplen=28 
SENT (2.5216s) ICMP 192.168.1.142 > 192.168.1.7 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (2.7717s) ICMP 192.168.1.142 > 192.168.1.4 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (3.0219s) ICMP 192.168.1.142 > 192.168.1.5 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
SENT (3.2724s) ICMP 192.168.1.142 > 192.168.1.5 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
RCVD (3.2730s) ICMP 192.168.1.5 > 192.168.1.142 Echo reply (type=0/code=0) ttl=64 id=34162 iplen=28 
SENT (3.5230s) ICMP 192.168.1.142 > 192.168.1.7 Echo request (type=8/code=0) ttl=64 id=53659 iplen=28 
^C 
Statistics for host 192.168.1.4: 
| Probes Sent: 4 | Rcvd: 0 | Lost: 4 (100.00%) 
|_ Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A 
Statistics for host 192.168.1.5: 
| Probes Sent: 4 | Rcvd: 3 | Lost: 1 (25.00%) 
|_ Max rtt: 0.391ms | Min rtt: 0.263ms | Avg rtt: 0.332ms 
Statistics for host 192.168.1.6: 
| Probes Sent: 4 | Rcvd: 0 | Lost: 4 (100.00%) 
|_ Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A 
Statistics for host 192.168.1.7: 
| Probes Sent: 3 | Rcvd: 0 | Lost: 3 (100.00%) 
|_ Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A 
Raw packets sent: 15 (420B) | Rcvd: 3 (138B) | Lost: 12 (80.00%) 
Tx time: 3.57078s | Tx bytes/s: 117.62 | Tx pkts/s: 4.20 
Rx time: 3.57078s | Rx bytes/s: 38.65 | Rx pkts/s: 0.84 
Nping done: 4 IP addresses pinged in 3.59 seconds