Created
September 24, 2015 13:49
-
-
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
This file contains hidden or 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 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