Is there any way or script that could ping and fetch the ttl simultaneously and store in two columns in a text file for a set of IP addresses that are alive on network- I wish to make a shell script that could help me make a load balance graph. Had tried with nmap and dig and fping command but couldn't get the desired output as asked. Working on CentOs 6.5


This simple script might do the job for you, if I have understood the question that is.


# List of IP or domain names

# Where to store the data?

# raw data per IP

# Clear the result each time or not? This will clear it each time
echo -n > "${outFile}"

for ip in $LIST
    raw=`ping -c 1 -t 255 "${ip}" | grep ttl | awk -F" |ttl=" '{ print $1 }'`
    if [ "$raw" != "" ]
        echo "${ip} ${raw}" >> $outFile
        echo "${ip} no-ping" >> $outFile

cat $outFile


The display would be something like: 64 64 64 no-ping
  • You just made my day brother @Tigger Thanks... – Pranjal Gupta Aug 18 '17 at 10:09
  • @PranjalGupta - Happy to have helped. – Tigger Aug 18 '17 at 23:14
  • Hye @Tigger, I am getting 64 as output i.e. from "64 bytes of data........." part of ping query since when I pinged the required IP with 2 packets the TTL was 127 and not 64 but the script you provided yield 64 as an answer which I think is 64 from "64 bytes of data...." part – Pranjal Gupta Aug 26 '17 at 19:09
  • @PranjalGupta You need to do some research in to TTL. From Time to live (wikipedia) A recommended initial value is 64 and also check this SuperUser Q&A what's the meaning of TTL=64?. – Tigger Aug 27 '17 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.