科学时遇到DNS解析的问题

发布时间 2023-11-10 13:46:15作者: 韩凯1990

问题:

  科学了,发现访问很慢,有时还无法访问,明显是被某种神秘的东方力量给阻断了。

DNS解析就起作用了。可以快速寻址,目前国内比较知名的且比较快的就是阿里云的:223.5.5.5。但是呢,这还需要看你自己的网络是哪家的,去访问国际的时候路由节点是否在国内来回的跳了。

 

为了自己能快速的找到属于自家网络最快的DNS解析服务器,我整理了全球公共的DNS IPv4的IP地址,如下

 1 114.114.114.114
 2 114.114.115.115
 3 119.29.29.29
 4 182.254.116.116
 5 101.226.4.6
 6 218.30.118.6
 7 123.125.81.6
 8 140.207.198.6
 9 1.2.4.8
10 210.2.4.8
11 8.8.8.8
12 8.8.4.4
13 1.1.1.1
14 1.0.0.1
15 9.9.9.9
16 185.222.222.222
17 185.184.222.222
18 208.67.222.222
19 208.67.220.220
20 199.91.73.222
21 178.79.131.110
22 223.5.5.5
23 223.6.6.6
24 183.60.83.19
25 183.60.82.98
26 180.76.76.76
27 4.2.2.1
28 4.2.2.2
29 122.112.208.1
30 139.9.23.90
31 114.115.192.11
32 116.205.5.1
33 116.205.5.30
34 122.112.208.175
35 139.159.208.206
36 180.184.1.1
37 180.184.2.2
38 168.95.192.1
39 168.95.1.1
40 203.80.96.10
41 203.80.96.9
42 199.85.126.10
43 199.85.127.10
44 216.146.35.35
45 216.146.36.36
46 64.6.64.6
47 64.6.65.6

具体的Python脚本如下

import time
import ping3  # 假设使用的是ping3库进行ping操作


def ping_ip(ip):
    ping_times = []
    for _ in range(5):  # Ping每个IP 5次
        start_time = time.time()
        response = ping3.ping(ip, timeout=1)  # 设置超时为1秒
        end_time = time.time()

        if response is not None:
            delay = end_time - start_time
            ping_times.append(delay)
    avg_response_time = sum(ping_times) / len(ping_times) if ping_times else None
    return ip, avg_response_time


# 全球公共dns ip
ips = [
    "114.114.114.114",
    "114.114.115.115",
    "178.79.131.110",
    "223.5.5.5",
    "223.6.6.6",
]
results = [ping_ip(ip) for ip in ips]

# 过滤掉没有有效响应时间的IP
results = [(ip, avg_response_time) for ip, avg_response_time in results if avg_response_time is not None]

# 按照平均响应时间排序结果
results.sort(key=lambda x: x[1])

# 打印延时最短的5个IP
print("延时最短的5个IP:")
for i in range(min(5, len(results))):
    print(f"{i + 1}. IP地址: {results[i][0]}, 平均响应时间: {results[i][1]:.3f} 秒")

  最后,我贴一张我当前网络最快的前5个DNS IP

 对应DNS查询链接:https://dnsdaquan.com/