TTL refers to the lifecycle of a network-layer package. You can use the echo TTL of ping to determine the operating system of a machine. (Although some system network parameters can be modified, but this value is rarely modified) the following script is relatively simple and must be run on a machine in the target network segment. Details :#! /Bin/sh # Check the entire network segment host system linux/windows/network device ip = "192
TTL refers to the lifecycle of a network-layer package. You can use the echo TTL of ping to determine the operating system of a machine. (Although the network parameters of some systems can be modified, this value is rarely modified)
The following script is simple and must be run on a machine in the destination CIDR block. The details are as follows:
#! /Bin/sh
# Check the host system linux/windows/network devices of the entire network segment
Ip = "192.168.113 ."
LOG =/root/ip. log
For I in 'seq 1 254'
Do
Ping-c 2 $ ip $ I> $ LOG
Okip = 'cat $ LOG | grep "ttl =" | awk-F' [: =] ''{print $4} '| sort | uniq'
Ttl = 'cat $ LOG | grep "ttl =" | awk-F' [: =] ''{print $9} '| sort | uniq'
If [$ ttl-eq 64]; then
Echo-e "\ e [32 mcheck $ okip is linux host \ e [0 m"
Elif [$ ttl-eq 128]; then
Echo-e "\ e [32 mcheck $ okip is windows host \ e [0 m"
Else
Echo-e "\ e [32 mcheck $ okip is VIP/network device/others \ e [0 m"
Fi
Done
Running result:
......
Check 192.168.113.152 is a linux host
Check 192.168.113.153 is a linux host
Check 192.168.113.154 is a windows Host
Check 192.168.113.155 is a linux host
Check 192.168.113.156 is windows Host
Check 192.168.113.157 is a windows Host
Check 192.168.113.158 is a linux host
Check 192.168.113.159 is a linux host
Check 192.168.113.160 is VIP/network device/others
Check 192.168.113.161 is VIP/network device/others
.......