views:

1831

answers:

6

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?

+2  A: 

Check if this blog post has what you need.

Ólafur Waage
+7  A: 

Broadcast ping:

$ ping 192.168.1.255
PING 192.168.1.255 (192.168.1.255): 56 data bytes
64 bytes from 192.168.1.154: icmp_seq=0 ttl=64 time=0.104 ms
64 bytes from 192.168.1.51: icmp_seq=0 ttl=64 time=2.058 ms (DUP!)
64 bytes from 192.168.1.151: icmp_seq=0 ttl=64 time=2.135 ms (DUP!)
...

(Add a -b option on Linux)

Ryan McGeary
note: you may need to add a "-b" in there depending on version/platform
Mark Renouf
Also, not all operating systems will respond to a broadcast ping (by default).
Mark Renouf
In IPv6 use "ff02::1".
Keltia
+1  A: 

en bash:

#!/bin/sh

COUNTER=1

while [ $COUNTER -lt 254 ]
do
   ping 192.168.1.$COUNTER -c 1
   COUNTER=$(( $COUNTER + 1 ))
done
David Rodríguez - dribeas
you might want to add a "-c 1" option to the ping command there...
Henrik Paul
+1  A: 

Under linux, I think ping -b 192.168.1.255 will work (192.168.1.255 is the broadcast address for 192.168.1.*) however IIRC that doesn't work under windows.

Axelle Ziegler
+2  A: 

The command line utility nmap can do this too:

nmap -sP 192.168.1.*

(IIRC)

christian studer
+13  A: 

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
Tom
Best answer to date because it is the first to be compatible with the reality that not all subnets are the same size, and using the /24 notation can be generalized to any size subnet.
Liudvikas Bukys