How can I do DNS lookups in Python, including referring to /etc/hosts?

前端 未结 6 1247
醉梦人生
醉梦人生 2020-11-27 14:51

dnspython will do my DNS lookups very nicely, but it entirely ignores the contents of /etc/hosts.

Is there a python library call which will do the right

6条回答
  •  再見小時候
    2020-11-27 15:15

    list( map( lambda x: x[4][0], socket.getaddrinfo( \
         'www.example.com.',22,type=socket.SOCK_STREAM)))
    

    gives you a list of the addresses for www.example.com. (ipv4 and ipv6)

提交回复
热议问题