Last active
January 1, 2016 13:38
-
-
Save Ginhing/aae1096546e94921990b to your computer and use it in GitHub Desktop.
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
from itertools import product | |
def expand(segment): | |
if '-' in segment: | |
start, end = map(int, segment.split('-')) | |
return map(str, range(start, end + 1)) | |
else: | |
return [segment] | |
def parse_ip(ip): | |
return [ '.'.join(_ip) for _ip in product( *map(expand, ip.split('.')) ) ] | |
if __name__ == "__main__": | |
print(parse_ip("192.168.1-10.1-10")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment