Friday 28 December 2012

bash code snippet to ping a public IP range in Linux

I was having an issue where traffic was not making it to the public interface of an ASA firewall that I was working on. I created this simple script to ping the public IP range. I was listening on the ASA side to see if the traffic made it through. This helped me track down that the issue was somewhere in the service providers equipment. Clearing the arp table on their equipment resolved the issue temporarily but it would re-appear. I believe we hit a bug in the equipment. The service providers equipment was replaced and the issue was resolved. I'm sure there is a smarter,cleaner or cooler way of doing this but I was in a hurry :)

First I made a file called "ping_list" and entered the IP addresses in the public range

xxx.xxx.xxx.69
xxx.xxx.xxx.70
xxx.xxx.xxx.71
xxx.xxx.xxx.72
xxx.xxx.xxx.73
xxx.xxx.xxx.74
xxx.xxx.xxx.75
xxx.xxx.xxx.76
xxx.xxx.xxx.77
xxx.xxx.xxx.78

Then I made a second file "ping-ip-range.sh" and entered the following code which just pings each IP only once then moves onto the next one.

for i in `cat ping_list`; do ping -c1 $i; done
Now I could ping the range by just running

./ping-ip-range.sh

You may need to chmod the .sh file to make it executable

chmod u+x ping-ip-range.sh

No comments:

Post a Comment