Skip to content

Commit

Permalink
config: 更新dns服务器
Browse files Browse the repository at this point in the history
  • Loading branch information
sinspired committed Dec 6, 2024
1 parent 919402d commit 286d627
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
12 changes: 10 additions & 2 deletions setDNS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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 = [
"排名",
Expand Down
42 changes: 31 additions & 11 deletions setHosts_Classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}秒")

Expand Down Expand Up @@ -491,7 +491,6 @@ async def wrapper(*args, **kwargs):
return wrapper
return decorator


LOGGING_CONFIG = {
"version": 1,
"handlers": {
Expand Down Expand Up @@ -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])

Expand All @@ -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"]):
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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", # 新加坡
Expand Down

0 comments on commit 286d627

Please sign in to comment.