getaddrinfo() display : IP Address « Network « Python Tutorial






import socket, sys
host, port = sys.argv[1:]

results = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)

for result in results:
    if result[0] == socket.AF_INET:
        print "Family: AF_INET"
    elif result[0] == socket.AF_INET6:
        print "Family: AF_INET6"
    else:
        print "Family:", result[0]

    if result[1] == socket.SOCK_STREAM:
        print "Socket Type: SOCK_STREAM"
    elif result[1] == socket.SOCK_DGRAM:
        print "Socket Type: SOCK_DGRAM"

    print "Protocol:", result[2]
    print "Canonical Name:", result[3]
    print "Socket Address:", result[4]








21.8.IP Address
21.8.1.Basic gethostbyaddr() example
21.8.2.Basic getaddrinfo() basic example
21.8.3.Basic getaddrinfo() list example
21.8.4.Perform a reverse lookup on the IP address given on the command line
21.8.5.getaddrinfo() display