1

Is there a way to do a command like ping 10.0.0.0 0.255.255.255 (wildcard masks), without installing a program, or a similar way to ping every node within a specific network/subnet?

I see something like ping -b for broadcast pings, but it does not seem to work (possibly because router does not accept this, but I am unsure).

Braiam
  • 67,791
  • 32
  • 179
  • 269
No Time
  • 1,073
  • 11
  • 25
  • 1
    You are looking for nmap. – Braiam May 28 '14 at 19:59
  • @Braiam I have used nmap before (I just wanted plain command, no download) – No Time May 28 '14 at 20:05
  • 1
    it is worth noting that ping doesn't guarantee host-discovery, because hosts may ignore ping requests. nmap is a much more reliable method, and is available for installation via apt - it may even already be installed on the system you're using. – James S. May 28 '14 at 20:13

1 Answers1

3

ping won't glob netmasks or wildcards.

You can flood ping the broadcast address of a subnet and monitor replies, though many routers will refuse to route ICMP over broadcast, because this is generally seens as abusive traffic. Additionally, only root can floodping with a zero interval.

For example:

ping -fb <BROADCAST ADDRESS>

Instead, you really ought to use NMAP in a friendly way.

ETA: if what you want is a list of node replies, we can get a little more clever:

ping -b -c 2 -i 20 <BROADCAST ADDRESS>

Where -b permits pinging a broadcast address, -c 2 tells ping to send two pings, -i 20 tells ping to wait twenty seconds between them.

What this gets you is a near-instant list of replies with a twenty-second wait before termination, followed by traffic statistics. The reason to make two ping echo requests is because if you set -c 1, ping will terminate on the very first response that it receives. We set twenty seconds between the two so that the list of replies is somewhat readable. It's a hack, but it works.

From here, you could suppress statistics output by piping to head -n-4 and then do useful awk tricks, sort, uniq and the like to build a useful one-liner report.

James S.
  • 761
  • The flood seemed good, I had to add interval (200 MS at minimum), so I changed your command to ping -fb -i 1 <Address> – No Time May 28 '14 at 19:37
  • I added a better, non-flood example. If you pipe it through a pager like less or more or redirect the output to a file, it'll make a fairly decent report of replies on a subnet. – James S. May 28 '14 at 19:57