使用chrome的小伙伴应该都知道有个页面一键翻译,对于英语相当蹩脚的我来说灰常好用,然而…
2010年,谷歌拒绝同意审查其在中国的搜索结果后,撤出了在中国的搜索引擎业务。
2017年,谷歌为中国用户推出了改进版的Google翻译应用。
2022 google translate 退出中国市场
…
google翻译最终还是退出了中国。
手动干预配置DNS,将google translate解析到提供服务的地区来达到效果。
使用以下脚本可以获取延迟较低的ip
windows下有一个很好用的快速修改hosts文件的工具SwitchHosts。
translate地址
import os
from concurrent.futures import ThreadPoolExecutor
from pyperclip import copy
os.system('title 查找最佳的谷歌翻译IP')
ipAndSpeed = []
ips = '''
142.250.4.90
172.253.114.90
172.217.203.90
172.253.112.90
142.250.9.90
172.253.116.90
142.250.97.90
142.250.30.90
142.250.111.90
172.217.215.90
142.250.11.90
142.251.9.90
108.177.122.90
142.250.96.90
142.250.100.90
142.250.110.90
172.217.214.90
172.217.222.90
142.250.31.90
142.250.126.90
142.250.10.90
172.217.195.90
172.253.115.90
142.251.5.90
142.250.136.90
142.250.12.90
142.250.101.90
172.217.192.90
142.250.0.90
142.250.107.90
172.217.204.90
142.250.28.90
142.250.125.90
172.253.124.90
142.250.8.90
142.250.128.90
142.250.112.90
142.250.27.90
142.250.105.90
172.253.126.90
172.253.123.90
172.253.62.90
142.250.98.90
172.253.113.90
'''
def ipList():
'''获取IP地址'''
return {i.strip() for i in ips.splitlines() if i.strip()}
def pingInfo(ip):
'''ping Ip 获取ms 最终取最小值'''
cmd = f'ping /n 1 {ip}'
for echoTxt in os.popen(cmd):
if '请求超时。' in echoTxt:
ipAndSpeed.append([ip, 999])
print(ip, '超时')
return
if echoTxt := echoTxt.strip():
echoTxt = echoTxt.replace(' ', '')
if ',平均=' in echoTxt:
ms = int(echoTxt.split('=')[-1].replace('ms', '')) # 分割平均=xxms
ipAndSpeed.append([ip, ms])
print(ip, f'{ms}ms')
return
def fastScan():
with ThreadPoolExecutor(20) as Pool: #使用线程池,设置20个线程,可修改
Pool.map(pingInfo, ipList())
print('正在加紧Ping,很快就好,请耐心等待!\n')
fastScan()
os.system('cls')
sortedSpeed = sorted(ipAndSpeed, key=lambda x: x[-1])
for n, i in enumerate(sortedSpeed, 1):
i[-1] = '超时' if i[-1] == 999 else f'{i[-1]}ms'
print(f'【{str(n).zfill(2)}】\t{i[0]}\t {i[1]}')
fastip, ms = sortedSpeed[0]
print(f'\n最佳IP是:【{fastip}】,响应时间:【{ms}】')
hostTxt = f'{fastip} translate.googleapis.com'
copy(hostTxt)
print(f'\n\n设置hosts的内容“已复制到剪贴板”: {hostTxt}\n\n\n按【任意键】打开hosts目录,然后【手动】修改。',
end='')
os.system('pause>nul')
os.popen('explorer /select,C:\Windows\System32\drivers\etc\hosts')
python多线程
ThreadPoolExecutor