A detailed description of the Getaddrinfo method of the socket module

Source: Internet
Author: User

The Getaddrinfo method is used to resolve DNS by URL

Import sys,socketdef dns_resolver (URL):    result = Socket.getaddrinfo (URL, None)    print (result[0][4][0]) if __ name__ = = ' __main__ ':    dns_resolver (' www.baidu.com ')

socket. getaddrinfo (host, Port[, Family[, Socktype[, Proto[, flags] ]])

return value: [(Family, Socktype, Proto, canonname, sockaddr)] has a list of tuples consisting of 5 elements, of which sockaddr is (Host,port)

    • Family: Represents the protocol cluster used by the socket. Common protocol families include Af_unix (native communication)/af_inet (IPV4 protocol in the TCP/IP protocol Cluster)/AF_INET6 (the IPV4 protocol in the TCP/IP protocol cluster). In Python's socket package, a 1 representation of af_unix,2 means that af_inet,10 represents Af_inet6.
    • SocketType: Represents the type of socket. Common socket types include sock_stream (TCP stream)/sock_dgram (UDP datagram)/sock_raw (raw sockets). Among them, sock_stream=1,sock_dgram=2,sock_raw=3
    • Proto: As the name implies, the protocol is specified. protocol used by the socket interface. If the caller does not want to specify, 0 is available. Commonly used protocols are, IPPROTO_TCP (=6) and IPPTOTO_UDP (=17), which correspond to TCP transport Protocol, UDP transport protocol respectively.

A detailed description of the Getaddrinfo method of the socket module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.