Reputation: 35
(Without the use of NMAP) I have used the TTL value to determine the OS being used on the target computer when user enters the IP. Actually, I had to hard code the TTL values in Case statement.
So my questions are:
Here is the sample code where I have used the TTL value to determine the OS being used:
#!/bin/bash
echo "Enter IP to find it's OS"
read ip
a=`ping -c 1 $ip|grep -w "ttl" | cut -c 41-47 | tr -d ' '`
echo $a
case "$a" in
ttl=64) echo "Linux Based";;
*) echo "other";;
esac
Upvotes: 2
Views: 274
Reputation: 92306
You cannot (reliably) use TTL to determine the OS. For example, you can easily change the default TTL on Linux using sysctl net.ipv4.ip_default_ttl=32
. Also, as you already found out, a lot of devices are using the same TTL.
To have a somewhat reliable detection, you need to check a variety of values to form a "fingerprint". See nmap's page about their OS detection to get an idea about what values can be used for such fingerprints.
The company I work for also wrote a similar OS detection for one of our products and it took us several man-days to implement and fine-tune this. I would not recommend to do it yourself if you can avoid it (unless you're doing it for fun because you want to learn something). If you really need to do this yourself, you will need access to a variety of devices for testing and read a lot about the details of IP, TCP and ICMP to get the data for your fingerprints. I doubt you can query the required fields using bash and standard UNIX/Linux tools, btw. You're going to need to do raw socket programming or need to use some third-party networking tools… in which case you could as well just use nmap
.
Upvotes: 1