python module for nslookup

后端 未结 9 824
渐次进展
渐次进展 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条回答
  •  -上瘾入骨i
    2020-12-10 01:15

    Previous answers are correct but here is what I would use socket, it "provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, MacOS, and probably additional platforms."

    import socket
    
    distinct_ips = []
    # 0,0,0,0  is for (family, type, proto, canonname, sockaddr)
    #change some_site.com to whatever your are looking up of course
    socket_info = socket.getaddrinfo("some_site.com",0,0,0,0)
    for result in socket_info:
        ns_ip = result[4][0]
        if distinct_ips.count(ns_ip)==0:
            distinct_ips.append(ns_ip)
            print(ns_ip)
    

提交回复
热议问题