Currently I'm looking into scripting and was writing something that will ping devices on a network, state if its reachable, and then take the ttl data from the ping and stating it's operating system.
I'm not completely familiar with how the grep command works but this is what I have so far:
for host in $(seq 1 255); do ping -c 1 $sn.$host | grep "Unreachable" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is Offline" fi ping -c 1 $sn.$host | grep "ttl" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is Online" fi done
How could I modify this script, knowing that Linux has a ttl of 64, Windows a ttl of 128, and ioS a ttl of 255 to make it output something like "$host is Online. Operating System: Linux"?
I know I could for example replicate the "ping -c 1 $sn.$host | grep "ttl"" line three times, adding the ttl value and creating the if statement that would print what I want, but I would like to get it done in one execution of ping if possible.