Basic gethostbyaddr() example : IP Address : Network PYTHON TUTORIALS


PYTHON TUTORIALS » Network » IP Address »

 

Basic gethostbyaddr() example


import sys, socket

def getipaddrs(hostname):
    result = socket.getaddrinfo(hostname, None, 0, socket.SOCK_STREAM)
    return [x[4][0for x in result]

hostname = socket.gethostname()
print "Host name:", hostname

print socket.getfqdn(hostname)
try:
    print ", ".join(getipaddrs(hostname))
except socket.gaierror, e:
    print "Couldn't not get IP addresses:", e



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Network
» IP Address