Skip to content

Instantly share code, notes, and snippets.

@Ginhing
Last active January 1, 2016 13:38
Show Gist options
  • Save Ginhing/aae1096546e94921990b to your computer and use it in GitHub Desktop.
Save Ginhing/aae1096546e94921990b to your computer and use it in GitHub Desktop.
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