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