Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NMAP continuous ping

I need to implement a code which is able to send ping packets each second toward a certain amount of destinations. The problem is that I'd like to ping as much destinations as possible inside 1 second window. For this reason I was thinking if there was a way to impose cycling into nmap [I mean something like -cycle nmap parameter] so that sockets would be opened only once and closed at the end of loop ping, saving way more time than using a "watch nmap" approach!

like image 648
NotoAnonimo Avatar asked Feb 08 '13 17:02

NotoAnonimo


Video Answer


2 Answers

Part of the Nmap project is the Nping tool. It is designed to do exactly what you want, and is very configurable. Here's an example run:

$ 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
like image 159
bonsaiviking Avatar answered Oct 12 '22 02:10

bonsaiviking


You could spawn multiple parallel nmap processes in the command line via:

nmap [options for destination 0] > output0 &

Spawn many such nmap requests for each destination while keeping a running index of the outputX files (output0, output1, etc).. When all your requests are complete, you can examine the contents of each output file

like image 43
Forhad Ahmed Avatar answered Oct 12 '22 02:10

Forhad Ahmed