This command obtains the host name from the IP address. For this task, we can use the gethostbyaddr() function. In this script, we obtain the host name from the IP address of 8.8.8.8.
You can find the following code in the socket_reverse_lookup.py file:
import sys, sockettry : result=socket.gethostbyaddr("8.8.8.8") print "The host name is:" print " "+result[0] print "\nAddress:" for item in result[2]: print " "+itemexcept socket.herror,e: print "error for resolving ip address:",e