Before I go ahead and write something myself is anyone aware of a library that can normalize a set of IP addresses. I manage an application where access is based on a range of IP address supplied from our clients. Most often this is small, but sometimes this list is 1,000+ horribly presented IP addresses.
for example
#INPUT #TO #OUTPUT
192.168.0-10.* -> 192.168.0.0-192.168.10.255
192.168.15.0-64 -> 192.168.15.0-192.168.15.64
192.10-15.*.* -> 192.10.0.0-192.15.255.255
192.168.1.1 -> 192.168.1.1-192.168.1.1
#YES, last case needed too,
#the scripit I have to convert to a CIDR range needs start and stop
This would preferably be done in python, but java or some sort of shell script would work too.
After wards I already have a script I’ve written to convert to the CIDR range and store these in our permissions table. I’m really just tried of doing this by hand several times a year. I think it is time to automate this a bit, just don’t want to reinvent the wheel here. It seems this might be a common enough problem
Both answers were helpfull, but neither answer my question. Which was if there exisited a library to do this already. I haven’t found one. It may be a worthwhile method to include of one of the other libraries that exist that focus on IPs. Adam’s Iptools was something that I found before asking this question.
My output did change a bit. I ended up returning a CIDR address and not a range. A few things could be simplified, and cleaned up. Also some error checking would be helpful. But this is what I used, with my rusty python and everything.