Monday, May 9, 2011

Ghetto-ized IP address range generator

Once i got my head out of my ass, I figured out an uber easy way to generate and sort a long list of IP addresses:

echo -e "\n"192.168.{1..255}.{1..255} #generates the actual IPs using Bash brace expansion
sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n #sorts the IPs into the proper order (optional)
>> hosts # output to file!

end result:
echo -e "\n"192.168.{1..255}.{1..255} | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n >> hosts

The only thing you would need to edit would be the original echo line to match the range you are trying to generate.

No comments:

Post a Comment