python module for nslookup

后端 未结 9 835
渐次进展
渐次进展 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:24

    the problem is that socket.gethostbyname() returns only one ip-address. nslookup returns as many as it has. I use:

    import subprocess
    
    process = subprocess.Popen(["nslookup", "www.google.com"], stdout=subprocess.PIPE)
    output = process.communicate()[0].split('\n')
    
    ip_arr = []
    for data in output:
        if 'Address' in data:
            ip_arr.append(data.replace('Address: ',''))
    ip_arr.pop(0)
    
    print ip_arr
    

    it will print:

    ['54.230.228.101', '54.230.228.6', '54.230.228.37', '54.230.228.80', '54.230.228.41', '54.230.228.114', '54.230.228.54', '54.230.228.23']
    

提交回复
热议问题