Skip to content

Commit

Permalink
pref: 弃用aiohttp,使用httpx,提高代码效率;优化代码逻辑,提高运行速度。
Browse files Browse the repository at this point in the history
  • Loading branch information
sinspired committed Dec 9, 2024
1 parent 15557c1 commit 7fcb50e
Show file tree
Hide file tree
Showing 5 changed files with 682 additions and 517 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ jobs:
with:
fetch-depth: 0

- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
pip install -U pyinstaller
- name: Build executables (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
for script in setDNS.py setHosts.py setHosts_Classic.py; do
pyinstaller --onefile "$script"
pyinstaller --clean --onefile "$script"
mv "dist/${script%.py}" "dist/${script%.py}-Linux-x64"
done
zip -j "cnNetTool-Linux-x64.zip" dist/*-Linux-x64
Expand All @@ -57,9 +57,9 @@ jobs:
$icoName = $script -replace '\.py$', '.ico'
if (Test-Path -Path $icoName) {
pyinstaller --onefile $script --uac-admin --icon $icoName
pyinstaller --clean --onefile $script --uac-admin --icon $icoName
} else {
pyinstaller --onefile $script --uac-admin
pyinstaller --clean --onefile $script --uac-admin
}
# pyinstaller --onefile $script --uac-admin
Expand All @@ -73,7 +73,7 @@ jobs:
if: matrix.os == 'macos-latest'
run: |
for script in setDNS.py setHosts.py setHosts_Classic.py; do
pyinstaller --onefile "$script"
pyinstaller --clean --onefile "$script"
mv "dist/${script%.py}" "dist/${script%.py}-macOS-x64"
done
zip -j "cnNetTool-macOS-x64.zip" dist/*-macOS-x64
Expand Down Expand Up @@ -144,4 +144,4 @@ jobs:
**/cnNetTool-Linux-x64.zip \
**/cnNetTool-Windows-x64.zip \
**/cnNetTool-macOS-x64.zip
shell: bash
shell: bash
4 changes: 3 additions & 1 deletion .github/workflows/update_hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- 'setHosts.py'
- 'setHosts_Classic.py'
- 'requirements.txt'
branches:
- 'main'
schedule:
- cron: '0 */4 * * *'
workflow_dispatch: # 允许手动触发
Expand Down Expand Up @@ -48,4 +50,4 @@ jobs:
add: |
hosts
README.md
push: "--force"
push: true
7 changes: 4 additions & 3 deletions README_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ pip install -r requirements.txt
### DNS 服务器工具 `SetDNS.py`

* --debug 启用调试日志
* --show-availbale-list, --list 显示可用dns列表,通过 --num 控制显示数量
* --best-dns-num BEST_DNS_NUM, --num 显示最佳DNS服务器的数量
* --show-availbale-list, --list, -l 显示可用dns列表,通过 --num 控制显示数量
* --best-dns-num BEST_DNS_NUM, --num, -n 显示最佳DNS服务器的数量
* --algorithm --mode {region,overall} 默认 `region` 平衡IPv4和ipv6 DNS,选择 `overall` 则会在所有IP中选择最快IP
* --show-resolutions, --show 显示域名解析结果
* --show-resolutions, --resolutions, -r 显示域名解析结果
* --only-global, --global 仅使用国际DNS服务器

### Hosts文件工具 `SetHosts.py`

Expand Down
47 changes: 13 additions & 34 deletions setDNS.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,13 @@
"ipv4": ["64.6.64.6", "64.6.65.6"],
"ipv6": ["2620:74:1b::1:1", "2620:74:1c::2:2"],
},
"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": []
},
"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": []
},
"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": []},
"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": []},
},
"中国大陆": {
"114DNS": {
Expand Down Expand Up @@ -309,7 +288,7 @@ def set_dns_servers(ipv4_dns_list: list[str], ipv6_dns_list: list[str]):
continue
if ipv4_dns_list:
logger.debug(
f"设置IPv4 DNS for {interface}: {
f"设置IPv4 DNS for {interface}:{
', '.join(ipv4_dns_list)}"
)
try:
Expand Down Expand Up @@ -516,11 +495,11 @@ def print_available_dns(available_dns, best_dns_num):


def get_input_with_timeout(prompt, timeout=10):
print(prompt, end="", flush=True)
# print(prompt, end="", flush=True)
user_input = []

def input_thread():
user_input.append(input())
user_input.append(input(prompt))

thread = threading.Thread(target=input_thread)
thread.daemon = True
Expand All @@ -529,7 +508,7 @@ def input_thread():
thread.join(timeout)
if thread.is_alive():
print("\n已超时,自动执行...")
return "y"
return "y", thread
print() # 换行
return user_input[0].strip() if user_input else "y", thread

Expand Down Expand Up @@ -598,7 +577,7 @@ def main():
set_dns_servers(recommended_dns["ipv4"], recommended_dns["ipv6"])
logger.info("DNS服务器已更新")
if thread.is_alive(): # 确认输入线程是否仍在运行
thread.join() # 等待线程完成
thread.join() # 等待线程完成
input("任务执行完毕,按任意键退出!")
else:
logger.info("操作已取消")
Expand Down Expand Up @@ -659,7 +638,7 @@ def run_as_admin():
"--list",
"-l",
action="store_true",
help="显示可用dns列表,通过 --num 控制娴熟数量",
help="显示可用dns列表,通过 --num 控制显示数量",
)
parser.add_argument(
"--best-dns-num",
Expand Down
Loading

0 comments on commit 7fcb50e

Please sign in to comment.