Simple ping sweeper with Bash

This is a piece of simple code demostrating how to do a ping sweeper using only Bash and ping, which are largely available in most Linux distro. It will ping and write online host IP address to a text file named “ping_result”.

Beware, it will delete the old file “ping_result” before doing the ping. So, it is best that you run it in an empty directory to prevent the risk to losing your file.

This simple piece of code will ping from to You should change it if you want to ping other addresses.



echo "Save to ping_result file in the current directory"

#Check if ping_result file exists
#If it does, delete it to make way for the new file
if test -e ping_result
rm ping_result
echo "File exist. Delete old file. Create new file"

for x in {188..189} #=>range from 188 to 189
for y in {125..130} #range from 125 to 130
#ping on to #write result to ping_result file
ping -c 1 192.168.$x.$y|grep "from"|cut -d " " -f 4| cut -d ":" -f 1>>ping_result