def expand_ipaddress_pattern(string, family):
 if (family not in [4, 6]):
  raise Exception('Invalid IP address family: {}'.format(family))
 if (family == 4):
  regex = IP4_EXPANSION_PATTERN
  base = 10
 else:
  regex = IP6_EXPANSION_PATTERN
  base = 16
 (lead, pattern, remnant) = re.split(regex, string, maxsplit=1)
 (x, y) = pattern.split('-')
 for i in range(int(x, base), (int(y, base) + 1)):
  if re.search(regex, remnant):
   for string in expand_ipaddress_pattern(remnant, family):
    (yield ''.join([lead, format(i, ('x' if (family == 6) else 'd')), string]))
  else:
   (yield ''.join([lead, format(i, ('x' if (family == 6) else 'd')), remnant]))

def expand_ipaddress_pattern ( string , family ) : if ( family not in [ 4 , 6 ] ) : raise Exception ( 'Invalid IP address family: {}' . format ( family ) ) if ( family == 4 ) : regex = IP4_EXPANSION_PATTERN base = 10 else : regex = IP6_EXPANSION_PATTERN base = 16 ( lead , pattern , remnant ) = re . split ( regex , string , maxsplit = 1 ) ( x , y ) = pattern . split ( '-' ) for i in range ( int ( x , base ) , ( int ( y , base ) + 1 ) ) : if re . search ( regex , remnant ) : for string in expand_ipaddress_pattern ( remnant , family ) : ( yield '' . join ( [ lead , format ( i , ( 'x' if ( family == 6 ) else 'd' ) ) , string ] ) ) else : ( yield '' . join ( [ lead , format ( i , ( 'x' if ( family == 6 ) else 'd' ) ) , remnant ] ) )
expand an ip address pattern into a list of strings .