From b651e8a0e9318fda2604339867336f4350e7e6b2 Mon Sep 17 00:00:00 2001 From: "prgrmz01@163.com" Date: Wed, 14 Dec 2022 10:05:29 +0800 Subject: [PATCH] dev, Update run-me.sh https://gitcode.net/pubx/github-hosts-deleted/-/commit/879b2315c072223f83674a823efac16f9b0bdfbd --- .gitignore | 2 +- README.md | 14 ++++++++++++++ fetch_ip_for_host/github_hosts_fetch.py | 4 ++-- fetch_ip_for_host/readme.md | 1 + fetch_ip_for_host/util.py | 4 ++-- run-me.sh | 4 ++-- 6 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 README.md create mode 100644 fetch_ip_for_host/readme.md diff --git a/.gitignore b/.gitignore index f74ccf7..b588164 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/.idea/ +**/.idea/ *.pyc **/__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d37fa8c --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# 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 +``` diff --git a/fetch_ip_for_host/github_hosts_fetch.py b/fetch_ip_for_host/github_hosts_fetch.py index 3ef7295..a0ed7c8 100644 --- a/fetch_ip_for_host/github_hosts_fetch.py +++ b/fetch_ip_for_host/github_hosts_fetch.py @@ -1,7 +1,7 @@ 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} " diff --git a/fetch_ip_for_host/readme.md b/fetch_ip_for_host/readme.md new file mode 100644 index 0000000..2f9fa3c --- /dev/null +++ b/fetch_ip_for_host/readme.md @@ -0,0 +1 @@ +> entrance is github_hosts_fetch.py \ No newline at end of file diff --git a/fetch_ip_for_host/util.py b/fetch_ip_for_host/util.py index b2c1d77..7914e9e 100644 --- a/fetch_ip_for_host/util.py +++ b/fetch_ip_for_host/util.py @@ -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 diff --git a/run-me.sh b/run-me.sh index b1f3544..d071469 100644 --- a/run-me.sh +++ b/run-me.sh @@ -1,7 +1,7 @@ #!/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" -- GitLab