Skip to content

Commit

Permalink
pref: 优化延迟测速,大幅提升性能;config: 增加更多DNS服务器,剔除解析结果较差的服务器
Browse files Browse the repository at this point in the history
  • Loading branch information
sinspired committed Dec 4, 2024
1 parent 31458a5 commit 3def7c5
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions setHosts_Classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def _sync_is_cert_valid(self, domain: str, ip: str, port: int = 443) -> bool:

except ConnectionError as e:
logging.debug(f"{domain} ({ip}): 连接被强迫关闭,ip有效 - {e}")
return False
return True
except Exception as e:
logging.debug(f"{domain} ({ip}): 证书验证失败 - {e}")
return False
Expand Down Expand Up @@ -957,10 +957,7 @@ def _sync_is_cert_valid_dict(self, domain: str, ip: str, latency: float, port: i
except ConnectionError as e:
logging.debug(f"{domain} ({ip}) {
latency:.0f}ms: 连接被强迫关闭,ip有效 - {e}")
rprint(f"{domain} ({ip}) {
latency:.0f}ms: 连接被强迫关闭,ip有效 - {e}")
input("按任意键继续...")
return (ip, latency, False)
return (ip, latency, True)
except Exception as e:
logging.debug(f"{domain} ({ip}) {latency:.0f}ms: 证书验证失败 - {e}")
return (ip, latency, False)
Expand Down Expand Up @@ -991,12 +988,9 @@ def _sync_is_cert_valid_dict_average(self, domains: List[str], ip: str, latency:
return (ip, latency, True) # 任意一个验证通过即返回成功

except ConnectionError as e:
# logging.debug(f"{domain} ({ip}) {
# latency:.0f}ms: 连接被强迫关闭,ip有效 - {e}")
rprint(f"[red]{domain} ({ip}) {
latency:.0f}ms: 连接被强迫关闭,ip有效[/red]")
# input("按任意键继续...\n")
continue # 检查下一个 domain
logging.debug(f"{domain} ({ip}) {
latency:.0f}ms: 连接被强迫关闭,ip有效 - {e}")
return (ip, latency, True)
except Exception as e:
logging.debug(f"{domain} ({ip}) {latency:.0f}ms: 证书验证失败 - {e}")
continue # 检查下一个 domain
Expand Down Expand Up @@ -1043,7 +1037,7 @@ def _print_results(self, best_hosts: List[Tuple[str, float]], latency_limit: int
end_time = datetime.now()
total_time = end_time - start_time
rprint(
f"[bold]运行时间:[/bold] [cyan]{total_time.total_seconds():.2f} 秒[/cyan]")
f"[bright_black]- 运行时间:[/bright_black] [cyan]{total_time.total_seconds():.2f} 秒[/cyan]")


# -------------------- Hosts文件管理 -------------------- #
Expand Down

0 comments on commit 3def7c5

Please sign in to comment.