Created
February 18, 2013 15:37
-
-
Save stestagg/4978271 to your computer and use it in GitHub Desktop.
Iterate over all IP addresses in a range..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_addr_range(start, end): | |
def to_int(ip): | |
return sum([int(p) << (24 - (8 * e)) for e, p in enumerate(ip.split("."))]) | |
def to_ip(val): | |
return ".".join(str((val & (0xff << s)) >> s) for s in range(24, -1, -8)) | |
for addr in xrange(to_int(start), to_int(end) + 1): | |
yield to_ip(addr) | |
for x in get_addr_range('0.0.0.0', '224.4.1.254'): | |
print x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment