Skip to content

Instantly share code, notes, and snippets.

@shanemhansen
Created July 16, 2014 18:00
Show Gist options
  • Save shanemhansen/0151d4d69002a9685b60 to your computer and use it in GitHub Desktop.
Save shanemhansen/0151d4d69002a9685b60 to your computer and use it in GitHub Desktop.
Enumerate IPS
#!/usr/bin/env python
import sys
(ip, mask) = sys.argv[1].split('/')
mask = int(mask)
def parseip(addr):
(a,b,c,d) = addr.split('.')
return int(d)*(256**0) + int(c)*(256**1) + int(b)*(256**2) + int(a)*(256**3)
def printip(numeric_ip):
d = numeric_ip&0xFF
c = (numeric_ip&0xFF00)>>8
b = (numeric_ip&0xFF0000)>>16
a = (numeric_ip&0xFF000000)>>24
return "%d.%d.%d.%d" % (a, b, c, d)
parsed_ip = parseip(ip)
for i in range(0, 2**mask):
print printip(parsed_ip+i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment