Skip to content

Instantly share code, notes, and snippets.

@alecnunn
Created September 24, 2015 13:49
Show Gist options
  • Select an option

  • Save alecnunn/32436e018f46f570d507 to your computer and use it in GitHub Desktop.

Select an option

Save alecnunn/32436e018f46f570d507 to your computer and use it in GitHub Desktop.
Get IPs in a specific range, such as: 192.168-180.1-5.0
def GetIPs(iprange):
nets = iprange.split('.')[1:-1]
firstOctet = nets[0].split('-')
secondOctet = nets[1].split('-')
ips = []
def get_range(r):
l = []
if len(r) != 2:
l.append(r[0])
else:
for i in range(int(r[0]), int(r[1]) + 1):
l.append(i)
return l
for n in get_range(firstOctet):
for m in get_range(secondOctet):
for i in range(256):
ips.append('{}.{}.{}.{}'.format(iprange.split('.')[0], str(n), str(m), str(i)))
return ips
for ip in GetIPs('192.168-180.1-5.0'):
print ip
for ip in GetIPs('192.168.1.0'):
print ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment