def is_local_device(my_ips, my_port, dev_ip, dev_port):
 candidate_ips = []
 if ((not is_valid_ip(dev_ip)) and is_valid_hostname(dev_ip)):
  try:
   addrinfo = socket.getaddrinfo(dev_ip, dev_port)
   for addr in addrinfo:
    family = addr[0]
    dev_ip = addr[4][0]
    if (family == socket.AF_INET6):
     dev_ip = expand_ipv6(dev_ip)
    candidate_ips.append(dev_ip)
  except socket.gaierror:
   return False
 else:
  if is_valid_ipv6(dev_ip):
   dev_ip = expand_ipv6(dev_ip)
  candidate_ips = [dev_ip]
 for dev_ip in candidate_ips:
  if ((dev_ip in my_ips) and ((my_port is None) or (dev_port == my_port))):
   return True
 return False

def is_local_device ( my_ips , my_port , dev_ip , dev_port ) : candidate_ips = [ ] if ( ( not is_valid_ip ( dev_ip ) ) and is_valid_hostname ( dev_ip ) ) : try : addrinfo = socket . getaddrinfo ( dev_ip , dev_port ) for addr in addrinfo : family = addr [ 0 ] dev_ip = addr [ 4 ] [ 0 ] if ( family == socket . AF_INET6 ) : dev_ip = expand_ipv6 ( dev_ip ) candidate_ips . append ( dev_ip ) except socket . gaierror : return False else : if is_valid_ipv6 ( dev_ip ) : dev_ip = expand_ipv6 ( dev_ip ) candidate_ips = [ dev_ip ] for dev_ip in candidate_ips : if ( ( dev_ip in my_ips ) and ( ( my_port is None ) or ( dev_port == my_port ) ) ) : return True return False
return true if the provided dev_ip and dev_port are among the ip addresses specified in my_ips and my_port respectively .