工作原因公司使用白名单的梯子访问方式,限制了可访问IP,一个个解析域名太麻烦,使用下面的python代码可以快速从多个DNS解析出需要访问域名的IP地址,代码如下:
import socket
def resolve_domain(domain, dns_servers):
resolved_ips = set()
for dns_server in dns_servers:
try:
ips = set(socket.gethostbyname_ex(domain)[-1])
resolved_ips.update(ips)
print(f"Resolved {domain} with DNS server {dns_server}: {', '.join(ips)}")
except socket.gaierror:
print(f"Failed to resolve {domain} with DNS server {dns_server}")
return resolved_ips
if __name__ == "__main__":
target_domains = ["openai.com", "ai.com", "challenges.cloudflare.com", "google.com","chat.openai.com","monica.im","accounts.google.com"]
# 编辑你想要获取IP的域名
dns_servers = ["202.96.209.133", "114.114.114.114", "223.5.5.5", "8.8.8.8"] # Add DNS server IPs you want to use here
#编辑你需要去解析的DNS地址
whitelist_file = "whitelist.txt"
all_resolved_ips = set()
for domain in target_domains:
resolved_ips = resolve_domain(domain, dns_servers)
all_resolved_ips.update(resolved_ips)
with open(whitelist_file, "w") as f:
for ip in all_resolved_ips:
f.write(ip + "\n")
print("Whitelist file created successfully!")
解析完后会在C:\Users\用户名\目录下生成一个whitelist.txt文件,就可以快速获得你需要的IP了。