python module for nslookup

后端 未结 9 861
渐次进展
渐次进展 2020-12-10 00:27

Is there a python-module that\'s doing the same stuff as nslookup does? I am planning to use nslookup on digging some information regarding the domain of a URL to be scrappe

9条回答
  •  渐次进展
    2020-12-10 01:15

    I'm using the following code:

    import socket
    
    ip_list = []
    ais = socket.getaddrinfo("www.yahoo.com",0,0,0,0)
    for result in ais:
      ip_list.append(result[-1][0])
    ip_list = list(set(ip_list))
    

    Or using a comprehension as:

    ip_list = list({addr[-1][0] for addr in socket.getaddrinfo(name, 0, 0, 0, 0)})
    

提交回复
热议问题