Problem: So recently i want to try to write a simple script to detect OS from a ping script( base on TTL(time-to-live))
Things i have tried: i have try some things like this
#!/bin/bash
sn=${1:-$1}
for host in $(seq 1 255); do
ttlstr=$(ping -c1 -w1 $sn.$host | grep -o 'ttl=[0-9][0-9]*') || {
printf "%s is Offline\n" "$sn.$host"
continue;
}
ttl="${ttlstr#*=}"
printf "%s is Online, ttl=%d\n" "$sn.$host" "$ttl"
if [ $ttl -eq 64 ]
then
echo "Operating is Linux"
elif [ $ttl -eq 128 ]
then
echo "Operating is Windows"
else
echo "Operating is IOS"
fi
done
- So as you can see it can ping every ip with the given Ip address. But if user want to enter:
192.168.1.0/24
how can i solve that ?
Lastly, thanks for your answer :D