github镜像网站访问github 一通过github镜像网站访问githubgithub镜像站点1https://bgithub.xyzgithub镜像站点2https://ggithub.xyz二、针对仓库经常容易被墙写个脚本批量检测代码层仓可不可达#!/usr/bin/env python3批量检测网址连通性HTTP 请求 TCP 回退importsocketimportsslimportsysimporttimeimporturllib.requestimporturllib.errorfromurllib.parseimporturlparsefromconcurrent.futuresimportThreadPoolExecutor,as_completed# 硬编码网址列表直接在这里添加URLS[https://hub.fastgit.xyz/,https://hub.fastgit.org/,https://cdn.githubjs.cf/,https://gitclone.com/,https://www.github.do/,https://ghproxy.com/,https://github.com/,https://bgithub.xyz,https://ggithub.xyz,]# 超时(秒)TIMEOUT4# 并发数CONCURRENCY64# 重试次数仅对疑似抖动的错误重试RETRY1HEADERS{User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36}# 忽略 SSL 证书校验避免证书问题导致误判_SSL_CTXssl.create_default_context()_SSL_CTX.check_hostnameFalse_SSL_CTX.verify_modessl.CERT_NONEdefhttp_check(url):先 HEAD/GET 快速验证失败则回退 TCP 探测rawurl.strip()ifnotraw.startswith((http://,https://)):rawhttp://raw last_errNoneforattemptinrange(RETRY1):try:starttime.time()# 用 HEAD 更快不下载 bodyrequrllib.request.Request(raw,headersHEADERS,methodHEAD)withurllib.request.urlopen(req,timeoutTIMEOUT,context_SSL_CTX)asresp:elapsed(time.time()-start)*1000coderesp.statusif200code400:returnurl,True,f{code}{elapsed:.0f}msreturnurl,False,fHTTP{code}excepturllib.error.HTTPErrorase:# 4xx/5xx 都说明服务器活着端口通视为可达elapsed(time.time()-start)*1000if400e.code600:returnurl,True,fHTTP{e.code}(可达){elapsed:.0f}mslast_errfHTTP{e.code}break# HTTP 错误无需重试excepturllib.error.URLErrorase:last_errstr(e.reason)# DNS 失败不重试ifName or service not knowninlast_errornodenameinlast_err:breakexceptsocket.timeout:last_err超时exceptExceptionase:last_errtype(e).__name__break# HTTP 全部失败 - TCP 端口探测更短超时parsedurlparse(raw)hostparsed.hostname portparsed.portor(443ifparsed.schemehttpselse80)ifhost:try:starttime.time()withsocket.create_connection((host,port),timeout2):elapsed(time.time()-start)*1000returnurl,False,fTCP通但HTTP失败({last_err}){elapsed:.0f}msexceptException:passreturnurl,False,last_error不可达defmain(urls):print(f\n{URL:50}{状态:8}{延迟/错误})print(-*80)ok,fail0,0results[]withThreadPoolExecutor(max_workersCONCURRENCY)asexecutor:futures{executor.submit(http_check,url):urlforurlinurlsifurl.strip()}forfutureinas_completed(futures):results.append(future.result())# 按原始顺序排序order{url.strip():ifori,urlinenumerate(urls)}results.sort(keylambdar:order.get(r[0].strip(),999))forurl,success,infoinresults:ifsuccess:print(f\033[32m{url:50}{OK:8}{info}\033[0m)ok1else:print(f\033[31m{url:50}{FAIL:8}{info}\033[0m)fail1print(f\n总计:{okfail}| ✓{ok}| ✗{fail})if__name____main__:ifURLS:urlsURLSeliflen(sys.argv)1:argsys.argv[1]try:withopen(arg)asf:urlsf.read().splitlines()exceptFileNotFoundError:urlssys.argv[1:]else:print(输入网址(每行一个空行结束):)urls[]whileTrue:lineinput()ifnotline:breakurls.append(line)main(urls)三、项目解释批量网址连通性检测工具使用 HTTP 请求 TCP 回退的方式多线程并发检测大量网址是否真正可访问纯 Python 标准库实现零依赖。原理用urllib发起真实 HTTP GET 请求并读取响应确认网页确实可达支持重试默认 2 次应对偶发抖动HTTP 失败时回退到 TCP 端口探测区分完全不通和端口通但服务异常HTTP 4xx 也视为可达服务器在响应忽略 SSL 证书校验避免证书问题误判比单纯 ping 或 TCP 探测更可靠有些服务器端口开着但网页已挂。使用方式方式一硬编码网址列表直接编辑check_urls.py中的URLS列表URLS[https://www.google.com,https://github.com,https://example.com,]然后运行python check_urls.py方式二从文件读取准备一个文本文件每行一个网址https://www.google.com https://github.com https://example.com运行python check_urls.py urls.txt方式三命令行直接传入python check_urls.py https://google.com https://github.com https://example.com方式四交互式输入python check_urls.py每行输入一个网址输入空行结束。注意如果URLS列表非空会优先使用硬编码列表忽略其他输入方式。配置项在脚本顶部可调整参数默认值说明TIMEOUT4单个请求超时时间秒CONCURRENCY64最大并发线程数RETRY1失败重试次数DNS/HTTP错误不重试输出示例URL 状态 延迟/错误 -------------------------------------------------------------------------------- https://example.com OK 200 234ms https://some-site.com/missing OK HTTP 404(可达) https://broken.com FAIL TCP通但HTTP失败(超时) 80ms https://unreachable.invalid FAIL DNS解析失败 总计: 4 | ✓ 2 | ✗ 2绿色 可通2xx/3xx红色 不通。