def ip_to_host(ip):
 try:
  (hostname, aliaslist, ipaddrlist) = socket.gethostbyaddr(ip)
 except Exception:
  hostname = None
 return hostname

def ip_to_host ( ip ) : try : ( hostname , aliaslist , ipaddrlist ) = socket . gethostbyaddr ( ip ) except Exception : hostname = None return hostname
returns the hostname of a given ip .