### 域名解析
import socket
def print_dns_resolution(domain):
try:
ip_address = socket.gethostbyname(domain)
print(f"域名 {domain} 解析的IP地址是: {ip_address}")
return ip_address
except socket.gaierror:
print(f"无法解析域名: {domain}")
return "None"
# 使用函数
body+="\r\n"
print("DNS解析测试")
body+="DNS解析测试"
body+="\r\n"
dnsList = ['nls.baidu.com','papi.baidu.com','newapi.baidu.com','static.baidu.com']
print(f"{'dns':30} {'resolv result':20}")
body+=f"{'dns':30} {'resolv result':20}"
body+="\r\n"
for dns in dnsList:
result = print_dns_resolution(dns)
print(f"{dns:30} {result:20}")
body += f"{dns:30} {result:20}"
body += "\r\n"
最后修改:2024 年 05 月 11 日
© 允许规范转载