Linux check all ips in a subnet with ping

Let’s say you have a subnet 192.168.1.0 / 24 and you want to scan all ip’s to see if any hosts are up:

Type the following command, enter:

 

$ for ip in $(seq 1 254); do ping -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo “192.168.1.$ip UP” || : ; done

Output:

192.168.1.65 UP
192.168.1.66 UP
192.168.1.70 UP
192.168.1.76 UP
192.168.1.253 UP
192.168.1.254 UP

Write a Reply or Comment

Your email address will not be published.