方式一:
# -*- coding: utf-8 -*- import socket ip = socket.gethostbyname("www.baidu.com") print(ip) # 39.156.66.14
方式二:
# -*- coding: utf-8 -*- import socket address_info = socket.getaddrinfo("www.baidu.com", None) ip = address_info[0][-1][0] print(ip) # 39.156.66.14