Shell uses the TTL return value to determine the host operating system in the network segment

Source: Internet
Author: User
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
.......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.