A quick script to iterate 255 ip addresses

While it didn’t take long at all, I figure it’s something to share for those that don’t do bash scripting.
I had the need to have 255 IP address changes (for network documentation so I didn’t have to type them that many times in documentation), so I created a simple bash script that walked through a variable and printed it out to the screen.
Now, this is simply for the 10.1.variable.x network to walk through from 10.1.variable.1 to 10.1.variable.255 so I could just import it as a CSV into Excel and copy-paste it to the right place.
NO, I hate Microsoft products. It’s just that now I have to document in a Microsoft Sharepoint web site which uses either ActiveX or Excel. Yes, morale is meant to be taken and destroyed, it’s only with a bastian of cold callousness I allow it to happen.
Here it is, have fun.
Just copy and paste this into a bash script, and call it with a number for the third octet of your network. Or change the networking address, or do whatever.

#!/bin/sh
THIRDOCTET=${1}
if [ ${THIRDOCTET} -n ]
then
echo “Variable missing.”
echo “Use the following: ${0} ”
exit
fi

for I in {1..255}
do
echo 10.1.${THIRDOCTET}.${I}
done

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s