This is probably not very cool, but it was interesting to think about.
Since the IP address space is 32 bits, you can write a function to convert IP addresses to unsigned 32-bit integers. You can then add or subtract 1 or as many as you want and convert back to an IP address. You do not have to worry about checking the range.
In the pseduo code for 192.123.34.134 you would do:
int i = (192 << 24) + (123 << 16) + (34 << 8) + 134
In general, for abcd:
int i = (a << 24) + (b << 16) + (c << 8) + d
Now change i as much as you want ( i++ , i+=10000 ) and go back:
String ip = (i >> 24) + "." + ((i >> 16) mod 256) + "." + ((i >> 8) mod 256) + "." + (i mod 256);
Sorry syntax - I could not write C ++ to save myself.
MK
monorailkitty
source share