我正在尝试获取所有IP地址:earth.all.vpn.airdns.org在Python中:
def hostnamesToIps(hostnames):
ip_list = []
for hostname in hostnames:
try:
ais = socket.getaddrinfo(hostname, None)
for result in ais:
#print (result[4][0])
ip_list.append(result[-1][0])
except:
eprint("Unable to get IP for hostname: " + hostname)
return list(set(ip_list))
Run Code Online (Sandbox Code Playgroud)
(f eprint是打印错误的函数).输出给了我29个地址.
但当我这样做时:
nslookup earth.all.vpn.airdns.org
Run Code Online (Sandbox Code Playgroud)
我得到大约100个托管.
如何在python中实现这一点?为什么我没有得到所有的"getaddrinfo"?
此行为仅使用Windows(python 3)出现.当我在我的Linux(python 2.7)上执行代码时,它给出了与使用nslookup相同的结果.
info:如答案所解释的那样,它不依赖于系统.
在不改变任何内容的情况下,nslookup和getaddrinfo的结果现在是相同的.