Friday, 3 April 2020

Bash script to List all the machines alive on a network

Ping all the machines alive

vi ping.sh
#!/bin/bash
#ping ping.sh

for ip in 192.168.0.{1..255} ;
do
 (
 ping $ip -c 2 &> /dev/null;

 if [ $? -eq 0 ];
 then
  echo $ip is alive
 fi
 )&
done
wait

./ping.sh
192.168.0.1 is alive
192.168.0.3 is alive
192.168.0.16 is alive
192.168.0.32 is alive
192.168.0.201 is alive


No comments:

Post a comment