Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send a ping to each IP on a subnet

Is there a command line based way to send pings to each computer in a subnet? Like

for(int i = 1; i < 254; i++)     ping(192.168.1.i); 

to enforce arp resolution?

like image 685
bot47 Avatar asked Feb 02 '09 13:02

bot47


People also ask

How do I ping multiple IP addresses at once?

While the ping command is used to ping a single host device to identify its existence, ping sweep helps to ping multiple IP addresses simultaneously. It's a basic network scanning technique used to determine the range of active and inactive IP addresses available on the network.

Can you ping a subnet?

Related. To monitor the number of existing ad-hoc clients on a wireless LAN, to identify devices that have set their own fixed addresses in the DHCP range or to take inventory of the devices currently connected to your network, you can ping each IP address in the subnet.


2 Answers

Not all machines have nmap available, but it's a wonderful tool for any network discovery, and certainly better than iterating through independent ping commands.

 $ nmap -n -sP 10.0.0.0/24  Starting Nmap 4.20 ( http://insecure.org ) at 2009-02-02 07:41 CST Host 10.0.0.1 appears to be up. Host 10.0.0.10 appears to be up. Host 10.0.0.104 appears to be up. Host 10.0.0.124 appears to be up. Host 10.0.0.125 appears to be up. Host 10.0.0.129 appears to be up. Nmap finished: 256 IP addresses (6 hosts up) scanned in 2.365 seconds 
like image 197
Tom Avatar answered Sep 23 '22 16:09

Tom


I would suggest the use of fping with the mask option, since you are not restricting yourself in ping.

fping -g 192.168.1.0/24 

The response will be easy to parse in a script:

192.168.1.1 is alive 192.168.1.2 is alive 192.168.1.3 is alive 192.168.1.5 is alive ... 192.168.1.4 is unreachable 192.168.1.6 is unreachable 192.168.1.7 is unreachable ... 

Note: Using the argument -a will restrict the output to reachable ip addresses, you may want to use it otherwise fping will also print unreachable addresses:

fping -a -g 192.168.1.0/24 

From man:

fping differs from ping in that you can specify any number of targets on the command line, or specify a file containing the lists of targets to ping. Instead of sending to one target until it times out or replies, fping will send out a ping packet and move on to the next target in a round-robin fashion.

More info: http://fping.org/

like image 26
Kyr Avatar answered Sep 22 '22 16:09

Kyr