关于chrome浏览器中谷歌翻译功能停服的应对方法
方案
- chrome中谷歌翻译使用的是
translate.googleapis.com
服务的API - 国内有一些还可以继续使用的服务
IP
- 只要找到可用的
IP
,然后在hosts中进行ip-host
映射即可使用翻译服务
解决
https://raw.githubusercontent.com/hcfyapp/google-translate-cn-ip/main/ips.txt
中有若干翻译服务ip
- 通过
ping
方式找到可用的ip
- ip太多了使用java代码找出可用ip
import java.net.InetAddress;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Ping {
public static boolean send(String ip) {
boolean flag = false;
try {
InetAddress inetAddress = InetAddress.getByName(ip);
flag = inetAddress.isReachable(3000);
}catch (Exception e) {}
return flag;
}
private static String[] 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.122.90", "172.253.62.90", "142.250.98.90", "142.250.185.238",
"142.251.116.101", "216.58.214.14", "142.250.189.206", "216.58.209.174", "142.250.203.142",
"142.250.218.14", "142.251.10.138", "142.251.40.174", "142.250.185.174", "172.217.16.46",
"172.217.0.46", "172.217.31.142", "216.58.220.142", "172.217.13.142", "172.253.113.90",
"108.177.97.100", "108.177.111.90", "108.177.125.186", "108.177.126.90", "108.177.127.90",
"142.250.1.90", "142.250.13.90", "142.250.99.90", "142.250.102.90", "142.250.103.90",
"142.250.113.90", "142.250.114.90", "142.250.115.90", "142.250.123.90", "142.250.138.90",
"142.250.141.90", "142.250.142.90", "142.250.145.90", "142.250.152.90", "142.250.153.90",
"142.250.157.90", "142.250.157.183", "142.250.157.184", "142.250.157.186", "142.250.158.90",
"142.250.159.90", "142.251.1.90", "142.251.2.90", "142.251.4.90", "142.251.6.90","142.251.8.90",
"142.251.10.90", "142.251.12.90", "142.251.15.90", "142.251.16.90", "142.251.18.90",
"142.251.107.90", "142.251.111.90", "142.251.112.90", "142.251.116.90", "142.251.117.90",
"142.251.120.90", "142.251.160.90", "142.251.161.90", "142.251.162.90", "142.251.163.90",
"142.251.166.90", "172.253.58.90", "172.253.63.90", "172.253.117.90", "172.253.118.90",
"172.253.119.90", "172.253.125.90", "172.253.127.90","216.58.227.65","216.58.227.66","216.58.227.67"
};
public static void main(String[] args) {
ExecutorService executorService = Executors.newFixedThreadPool(10);
List<CompletableFuture> futures = new ArrayList<>();
List<Map.Entry<String,Long>> entries = new ArrayList<>(ips.length);
for (String ip : ips) {
CompletableFuture future = CompletableFuture.runAsync(()->{
long start = System.currentTimeMillis();
if (send(ip)) {
long end = System.currentTimeMillis();
entries.add(new AbstractMap.SimpleEntry<>(ip,end - start));
}
System.out.printf(".");
},executorService);
futures.add(future);
}
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
executorService.shutdown();
System.out.println("\nok...");
Collections.sort(entries, (o1, o2) -> (int) (o1.getValue() - o2.getValue()));
entries.forEach(x -> System.out.println(x));
}
- 代码打印出的第一个ip一般是响应时间最短的,所以就用第一个
- 找到电脑中的hosts文件,win10在
C:\Windows\System32\drivers\etc\
目录下,由于权限问题,可以拖出来改好在放回去 - 编辑hosts文件,在最后一行加入
108.177.97.100 translate.googleapis.com
,前面的ip就是代码打印的ip
不积跬步无以至千里