Search code examples
linuxperformancebashnetworkingping

Fastest way to ping a network range and return responsive hosts?


Constraints:
1. Speed matters.
2. I am allowed to ping once.

I'm debating whether to use Python or shellscripting. Is there a method faster than bash?

Here is the current code,

for ip in $(seq int1 int2); do
    ping -c 1 xxx.xxx.xxx.$ip | grep "bytes from" &
done

Anything faster than this?


Solution

  • You should use nmap:

    nmap -T5 -sn 192.168.0.0-255
    nmap -T insane -sn 192.168.0.0-255 # same as above but w/named template
    

    The -T 5/insane option uses the "insane" template, which:

    insane mode assumes that you are on an extraordinarily fast network or are willing to sacrifice some accuracy for speed. -T4 (aggressive) prohibits the dynamic scan delay from exceeIf you are on a decent broadband or ethernet connection, I would recommend always using -T4. Some people love -T5 though it is too aggressive ding 10 ms for TCP ports and -T5 (insane) caps that value at 5 ms. If you are on a decent broadband or ethernet connection, I would recommend always using -T4. Some people love -T5 though it is too aggressive for my taste.

    The -sn option means "no port scan":

    This option tells Nmap not to do a port scan after host discovery, and only print out the available hosts that responded to the host discovery probes. This is often known as a “ping scan”, but you can also request that traceroute and NSE host scripts be run. This is by default one step more intrusive than the list scan, and can often be used for the same purposes. It allows light reconnaissance of a target network without attracting much attention. Knowing how many hosts are up is more valuable to attackers than the list provided by list scan of every single IP and host name.