A while ago I faced a situation where I had to discover the online computers in our network and I ended coding the following small shell script which basically try to detect them by ping:

#!/bin/bash

if [ "$#" != "3" ]; then
    echo "Invalid script call. Use './map-network.sh <base> <a> <b>' (eg 192.168.0. 100 199)"
else
    base=$1
    a=$2
    b=$3
   
    echo "Mapping network from $base$a to $base$b"
   
    for i in `seq $a $b`;
    do
        ret=`ping -c 1 -W 1 $base$i`
        proc=`echo $ret | awk '{split($13,a,"="); print a[1]}'`
       
        if [ "$proc" = "ttl" ]; then
            echo "$base$i is active"
        fi
    done
fi
 

But today I realized my naivety and learned that nmap is a faster and better tool for the job! The exactly same result is achieved by executing the following code in the terminal:

$ nmap -sP 192.168.0.*

There is also a more interesting variation which, given a range, looks for the current open ports in each computer:

$ nmap -sP 192.168.0.*
$ sudo nmap -sS -p 1-1024 192.168.0.*

That's it... I hope this article helps someone else other than myself in the future :D