def __ip_addr(addr, address_family=socket.AF_INET):
 mask_max = '32'
 if (address_family == socket.AF_INET6):
  mask_max = '128'
 try:
  if ('/' not in addr):
   addr = '{addr}/{mask_max}'.format(addr=addr, mask_max=mask_max)
 except TypeError:
  return False
 (ip, mask) = addr.rsplit('/', 1)
 try:
  socket.inet_pton(address_family, ip)
 except socket.error:
  return False
 try:
  mask = int(mask)
 except ValueError:
  return False
 else:
  if (not (1 <= mask <= int(mask_max))):
   return False
 return True

def __ip_addr ( addr , address_family = socket . AF_INET ) : mask_max = '32' if ( address_family == socket . AF_INET6 ) : mask_max = '128' try : if ( '/' not in addr ) : addr = '{addr}/{mask_max}' . format ( addr = addr , mask_max = mask_max ) except TypeError : return False ( ip , mask ) = addr . rsplit ( '/' , 1 ) try : socket . inet_pton ( address_family , ip ) except socket . error : return False try : mask = int ( mask ) except ValueError : return False else : if ( not ( 1 <= mask <= int ( mask_max ) ) ) : return False return True
returns true if the ip address are valid .