Shell script: Ping All IPs of a network segment and display the current time in one second

Source: Internet
Author: User
Label: shell script ping all ips on the same network segment

The environment is centos7 / bin / bash

Note When copying the test, be sure to change the ip network segment in the example to your own ip network segment.

ctrl + z can enter the script into the background, and then kill the process.

1.

#! / bin / bash



for i in {1..254} #define 1 to 254

do

HOST = 192.168.168. $ I

ping -c 2 $ HOST &> / dev / null

if [$? -eq 0]; then # -eq Determine if the return value is 0 $? A value of 0 means the execution result is correct

echo "$ HOST IS UP"

else

echo "$ HOST IS DOWN"

fi

done



2.

#! / bin / sh



ip = "192.168.168."

for i in {1..254} #define 1 to 254 IP numbers

#for i in `seq 1 254` can also be expressed like this

do

  ping -c 2 $ ip $ i | grep -q ‘ttl =‘ && echo "$ ip $ i yes" || echo "$ ip $ i no"

#ping -c 2 ping2 times Filter ttl in the output. If ttl =, then output echo "$ ip $ i yes otherwise output no

done



3.

#! / bin / sh



ip = 1 #Describe the starting IP

while [$ ip! = 254]; # ip max

do

ping 192.168.168. $ ip -c 2 | grep -q ‘ttl =‘ && echo "192.168.168. $ ip yes" || echo "192.168.168. $ ip no"

ip = `expr" $ ip "" + "" 1 "` # $ ip + 1 every time

done



Display the current time every second

#! / bin / bash

for now in {1..5000};

do

echo "current time: $ (date‘ +% T ‘)”; #date only takes the time parameter

sleep 1; #delay for one second

done





Shell script: ping all IPs on a network segment and display the current time every second
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.