zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Python 域名转IP(可包含http、https)

2023-09-11 14:14:44 时间
import socket
import tldextract

def get_ip(domain):
    ip = ''
    limit = 5
    domain = tldextract.extract(domain).fqdn
    while limit:
        try:
            ip = socket.gethostbyname(domain)
            break
        except Exception as e:
            limit -= 1
    return ip

print(get_ip(www.baidu.com))