def getIP(domain):
myaddr = socket.getaddrinfo(domain, 'http')
print(myaddr[0][4][0])
执行函数
getIP(“www.google.com”)
def get_ip_list(domain): # 获取域名解析出的IP列表
ip_list = []
try:
addrs = socket.getaddrinfo(domain, None)
for item in addrs:
if item[4][0] not in ip_list:
ip_list.append(item[4][0])
except Exception as e:
# print(str(e))
pass
return ip_list