From 286d62771f41e7ed31da24c317d6a3b59b963a35 Mon Sep 17 00:00:00 2001 From: sinspired Date: Fri, 6 Dec 2024 15:11:59 +0800 Subject: [PATCH] =?UTF-8?q?config:=20=E6=9B=B4=E6=96=B0dns=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setDNS.py | 12 ++++++++++-- setHosts_Classic.py | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/setDNS.py b/setDNS.py index 916761c..31f8d9f 100644 --- a/setDNS.py +++ b/setDNS.py @@ -60,11 +60,19 @@ }, "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": []}, + "CPC HK": {"ipv4": ["210.184.24.65", "152.101.4.130"], "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": []}, + "Amazon.HK": {"ipv4": ["18.163.103.200"]}, + "IPTELECOM.HK": {"ipv4": ["43.251.159.130"]}, + "Broadband Network.HK": {"ipv4": ["14.198.168.140"]}, + "HKT.HK": {"ipv4": ["203.198.161.89"]}, + "Cloudie.HK": {"ipv4": ["103.51.144.212"]}, + "Dimension.HK": {"ipv4": ["66.203.146.122"]}, + "ONL.HK": {"ipv4": ["103.142.147.14"]}, + "SkyExchange.HK": {"ipv4": ["156.241.7.91"]}, }, "中国大陆": { "114DNS": { @@ -471,7 +479,7 @@ def print_available_dns(available_dns, best_dns_num): if available_dns[ip_version]: # 使用PrettyTable展示前 n 个DNS服务器信息 table = PrettyTable() - best_dns_num=min(len(available_dns[ip_version]),best_dns_num) + best_dns_num = min(len(available_dns[ip_version]), best_dns_num) table.title = f"前 {best_dns_num} 个可用 {ip_version.upper()} DNS服务器" table.field_names = [ "排名", diff --git a/setHosts_Classic.py b/setHosts_Classic.py index cc8539f..ba6c323 100644 --- a/setHosts_Classic.py +++ b/setHosts_Classic.py @@ -342,7 +342,7 @@ async def resolve_domain(self, domain: str) -> Set[str]: ips.update(dns_ips) dns_resolve_end_time = datetime.now() - + dns_resolve_duration = dns_resolve_end_time - start_time logging.debug(f"DNS解析耗时: {dns_resolve_duration.total_seconds():.2f}秒") @@ -491,7 +491,6 @@ async def wrapper(*args, **kwargs): return wrapper return decorator - LOGGING_CONFIG = { "version": 1, "handlers": { @@ -639,7 +638,7 @@ async def get_lowest_latency_hosts( else: rprint("[red]延迟检测没有获得有效IP[/red]") return [] - + # 排序结果 valid_latency_ips = sorted(valid_latency_ips, key=lambda x: x[1]) @@ -653,7 +652,7 @@ async def get_lowest_latency_hosts( r for r in valid_latency_ips if not Utils.is_ipv6(r[0])] ipv6_results = [ r for r in valid_latency_ips if Utils.is_ipv6(r[0])] - + # 第二步:使用线程池并发验证SSL证书 # if "github" in group_name.lower(): if len(valid_latency_ips) > 1 and any(keyword in group_name.lower() for keyword in ["google"]): @@ -855,7 +854,7 @@ def _select_best_hosts(self, valid_results: List[Tuple[str, float]]) -> List[Tup best_hosts = [] selected_count = 0 - + if ipv4_results: min_ipv4_results = min(ipv4_results, key=lambda x: x[1]) @@ -1043,13 +1042,13 @@ def __init__( async def update_hosts(self): # 更新hosts文件的主逻辑 all_entries = [] - + for i, group in enumerate(self.domain_groups, 1): progress_str = Utils.get_align_str(i, group.name) rprint(progress_str) # 先获取预设IP default_ips = group.ips.copy() - + # 2. 根据不同组设置IP if group.group_type == GroupType.SEPARATE: for domain in group.domains: @@ -1062,7 +1061,7 @@ async def update_hosts(self): len(default_ips)}[/bold bright_green] 个预设IP地址[/bright_black]" ) all_ips.update(default_ips) - + resolved_ips = await self.resolver.resolve_domain(domain) all_ips.update(resolved_ips) @@ -1092,14 +1091,15 @@ async def update_hosts(self): len(default_ips)}[/bold bright_green] 个预设IP地址[/bright_black]" ) all_ips.update(default_ips) - + # 收集组内所有域名的DNS解析结果 domain_resolve_tasks = [self.resolver.resolve_domain( domain) for domain in group.domains] resolved_ips = await asyncio.gather(*domain_resolve_tasks, return_exceptions=True) - all_ips.update(ip for ip_list in resolved_ips for ip in ip_list if ip) - + all_ips.update( + ip for ip_list in resolved_ips for ip in ip_list if ip) + if not all_ips: logging.warning(f"组 {group.name} 未找到任何可用IP。跳过该组。") continue @@ -1655,6 +1655,26 @@ class Config: "provider": "CPC HK", # 香港 "type": "ipv4" }, + { + "ip": "18.163.103.200", + "provider": "Amazon HK", # 香港 + "type": "ipv4" + }, + { + "ip": "43.251.159.130", + "provider": "IPTELECOM HK", # 香港 + "type": "ipv4" + }, + { + "ip": "14.198.168.140", + "provider": "Broadband HK", # 香港 + "type": "ipv4" + }, + { + "ip": "66.203.146.122", + "provider": "Dimension HK", # 香港 + "type": "ipv4" + }, { "ip": "118.201.189.90", "provider": "SingNet", # 新加坡