提交 b651e8a0 编写于 作者: P prgrmz01@163.com
上级 a34708e2
/.idea/
**/.idea/
*.pyc
**/__pycache__/
\ No newline at end of file
# how to run
### microsoft windows
```bash
git clone https://gitcode.net/pubx/github-hosts.git
explorer ./github-hosts/
#run run-me.bat as administrator
```
### linux
```bash
git clone https://gitcode.net/pubx/github-hosts.git
cd github-hosts ; sudo run-me.sh
```
from typing import List
from get_from_www_ipaddress_com import fetchIpFrom__www_ipaddress_com
from util import accessIpRootPathWebNanoSeconds, findMiniValueWithIdx, replaceOsHostFile
from util import accessIpRootPathWebNanoSeconds, findMiniValueWithIdx, replaceOsHostFile, _1S_AS_NS
#https://www.ipaddress.com/site/github.global.ssl.fastly.net
......@@ -16,7 +16,7 @@ def findFastIp_in_IpListForHostK(k, hostK, _ipKLs)->str:
print(f"try find fast ip : {hostK}, {_ipKLs}")
ns_ls:List[int]=[accessIpRootPathWebNanoSeconds(ipJ) for j,ipJ in enumerate(ipKLs)]
j,_ns= findMiniValueWithIdx(ns_ls)
print(f"{hostK}:fast ip is :in idx {j},{ipKLs[j]},{_ns/(10^6)}ms")
print(f"{hostK}:fast ip is :in idx {j},{ipKLs[j]},{_ns/_1S_AS_NS:.2f}s")
return f"{ipKLs[j]} {hostK} #{' '.join([*ipKLs[0:j], *ipKLs[j+1:]])}"
else: # len(ipKLs) == 1
return f"{ipKLs[0]} {hostK} "
......
> entrance is github_hosts_fetch.py
\ No newline at end of file
......@@ -11,7 +11,7 @@ def accessIpRootPathWebNanoSeconds(ipJ:str,sleepSeconds:float=0.1)->int:
time.sleep(sleepSeconds)
begin:int=time.time_ns()
url:str=f"http://{ipJ}"
print(f"request {url}")
print(f"request {url},",end="")
try:
__response:requests.models.Response=requests.get(url=url,timeout=7)
except (requests.exceptions.ReadTimeout,requests.exceptions.ConnectionError) as e:
......@@ -24,7 +24,7 @@ def accessIpRootPathWebNanoSeconds(ipJ:str,sleepSeconds:float=0.1)->int:
end:int=time.time_ns()
delta_ns:int=end-begin
print(f"debug:{delta_ns}ns,{delta_ns/_1S_AS_NS}s")
print(f"cost:{delta_ns/_1S_AS_NS}s")
return delta_ns
......
#!/bin/bash
cd ./fetch_ip_for_host/
which python || (echo "exit,because:python not found. please insert python3 ,then set it to env PATH"; exit 2)
python -c "print('this is python3')" || (echo "exit,because:python2 found but python3 not found. please insert python3 ,then set it to env PATH"; exit 4)
pip install -r requirements.txt|| (echo "exit,because:pip dependency install failed. please run github_hosts_fetch.py manual"; exit 4)
echo "environment is ok, now run github_hosts_fetch.py"
cd ./fetch_ip_for_host/
python github_hosts_fetch.py && echo "ok,now you can access https://github.com at your browser"
\ No newline at end of file
python github_hosts_fetch.py && echo "ok,now you can access https://github.com at your browser"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册