Skip to content

Commit

Permalink
chore: 更新文件
Browse files Browse the repository at this point in the history
  • Loading branch information
sinspired committed Dec 5, 2024
1 parent 10e9094 commit b39748a
Showing 1 changed file with 13 additions and 35 deletions.
48 changes: 13 additions & 35 deletions setDNS.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,13 @@
"ipv4": ["64.6.64.6", "64.6.65.6"],
"ipv6": ["2620:74:1b::1:1", "2620:74:1c::2:2"],
},
"NTT Communications DNS": {
"ipv4": ["129.250.35.250"],
"ipv6": []
},
"KT DNS": {
"ipv4": ["168.126.63.1"],
"ipv6": []
},
"CPC HK": {
"ipv4": ["210.184.24.65"],
"ipv6": []
},
"Soft Bank": {
"ipv4": ["101.110.50.106"],
"ipv6": []
},
"SingNet": {
"ipv4": ["118.201.189.90"],
"ipv6": []
},
"SK Broadband": {
"ipv4": ["1.228.180.5"],
"ipv6": []
},
"Korea Telecom": {
"ipv4": ["183.99.33.6"],
"ipv6": []
},
"NTT Communications DNS": {"ipv4": ["129.250.35.250"], "ipv6": []},
"KT DNS": {"ipv4": ["168.126.63.1"], "ipv6": []},
"CPC HK": {"ipv4": ["210.184.24.65"], "ipv6": []},
"Soft Bank": {"ipv4": ["101.110.50.106"], "ipv6": []},
"SingNet": {"ipv4": ["118.201.189.90"], "ipv6": []},
"SK Broadband": {"ipv4": ["1.228.180.5"], "ipv6": []},
"Korea Telecom": {"ipv4": ["183.99.33.6"], "ipv6": []},
},
"中国大陆": {
"114DNS": {
Expand Down Expand Up @@ -208,7 +187,8 @@ def find_available_dns(args) -> tuple[dict, dict]:
domain_resolutions[domain][server] = ips

logger.debug(
f"{ip_version.upper()} DNS {server} ({region} - {provider}) 成功率 {success_rate:.2%}, 平均延迟 {avg_response_time:.2f}ms")
f"{ip_version.upper()} DNS {server} ({region} - {provider}) 成功率 {success_rate:.2%}, 平均延迟 {avg_response_time:.2f}ms"
)
except Exception as exc:
logger.error(f"{server} 测试出错: {str(exc)}")

Expand Down Expand Up @@ -308,7 +288,7 @@ def set_dns_servers(ipv4_dns_list: list[str], ipv6_dns_list: list[str]):
if ipv4_dns_list:
logger.debug(
f"设置IPv4 DNS for {interface}:{
', '.join(ipv4_dns_list)}"
', '.join(ipv4_dns_list)}"
)
try:
subprocess.run(
Expand Down Expand Up @@ -460,8 +440,7 @@ def print_recommended_dns_table(dns_list: list, ip_version: str, available_dns:
if dns:
# 在best_dns列表中查找正确的服务器信息
server_info = next(
(info for server,
info in available_dns[ip_version] if server == dns),
(info for server, info in available_dns[ip_version] if server == dns),
None,
)
if server_info:
Expand Down Expand Up @@ -571,8 +550,7 @@ def main():
print_domain_resolutions(domain_resolutions, dns_performance)

# 防止 best_dns_num 数值超过数组长度
num_servers = min(
len(available_dns["ipv4"]), len(available_dns["ipv6"]))
num_servers = min(len(available_dns["ipv4"]), len(available_dns["ipv6"]))
if args.best_dns_num > num_servers:
args.best_dns_num = num_servers

Expand All @@ -596,7 +574,7 @@ def main():
set_dns_servers(recommended_dns["ipv4"], recommended_dns["ipv6"])
logger.info("DNS服务器已更新")
if thread.is_alive(): # 确认输入线程是否仍在运行
thread.join() # 等待线程完成
thread.join() # 等待线程完成
input("任务执行完毕,按任意键退出!")
else:
logger.info("操作已取消")
Expand Down

0 comments on commit b39748a

Please sign in to comment.