2022-04-06 17:49:00 +08:00
|
|
|
package top.octopusyan.config;
|
|
|
|
|
2022-04-09 03:59:20 +08:00
|
|
|
import lombok.Getter;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
2022-04-06 17:49:00 +08:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author : octopus yan
|
|
|
|
* @email : octopus_yan@foxmail.com
|
|
|
|
* @description : 代理设置
|
|
|
|
* @create : 2022-4-5 18:14
|
|
|
|
*/
|
|
|
|
public class ProxyConfig {
|
2022-04-09 03:59:20 +08:00
|
|
|
private static final Map<String, String> serverPath = new HashMap<>();
|
|
|
|
private static final Map<String, String> serverIp = new HashMap<>();
|
|
|
|
private static final Map<String, Integer> typePort = new HashMap<>();
|
2022-04-06 17:49:00 +08:00
|
|
|
|
|
|
|
static {
|
|
|
|
serverPath.put("香港", "xg.frp.octopusyan.top");
|
|
|
|
serverPath.put("北京", "bj.frp.octopusyan.top");
|
|
|
|
serverPath.put("上海", "frp.octopusyan.top");
|
|
|
|
|
2022-04-09 03:59:20 +08:00
|
|
|
serverIp.put("香港", "101.32.202.135");
|
|
|
|
serverIp.put("北京", "112.125.120.135");
|
|
|
|
serverIp.put("上海", "81.68.214.67");
|
|
|
|
|
2022-04-06 17:49:00 +08:00
|
|
|
typePort.put("http", 80);
|
|
|
|
typePort.put("https", 80);
|
|
|
|
typePort.put("ssh", 22);
|
|
|
|
typePort.put("tcp", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-09 03:59:20 +08:00
|
|
|
@Getter
|
2022-04-06 17:49:00 +08:00
|
|
|
public enum ProxyServer {
|
2022-04-09 03:59:20 +08:00
|
|
|
xg("香港", 1),
|
|
|
|
bj("北京", 2),
|
|
|
|
sh("上海", 3);
|
|
|
|
private final String serverName;
|
|
|
|
private final int value;
|
|
|
|
|
|
|
|
ProxyServer(String serverName, int value) {
|
|
|
|
this.serverName = serverName;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ProxyServer valueOf(int node) {
|
|
|
|
for (ProxyServer value : values()) {
|
|
|
|
if (value.value == node) return value;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2022-04-06 17:49:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum ProxyType {
|
|
|
|
HTTP("http"),
|
|
|
|
HTTPS("https"),
|
|
|
|
SSH("tcp"),
|
|
|
|
TCP("tcp"),
|
|
|
|
;
|
|
|
|
|
2022-04-09 03:59:20 +08:00
|
|
|
private final String type;
|
2022-04-06 17:49:00 +08:00
|
|
|
|
|
|
|
public String getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyType(String type) {
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getServerPath(String serverName) {
|
|
|
|
return serverPath.get(serverName);
|
|
|
|
}
|
|
|
|
|
2022-04-09 03:59:20 +08:00
|
|
|
public static int getServerNode(String serverName) {
|
|
|
|
for (ProxyServer server : Arrays.asList(ProxyServer.values())) {
|
|
|
|
if(server.serverName.equals(serverName)) return server.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取服务名称
|
|
|
|
* @param node 服务器标签
|
|
|
|
*/
|
|
|
|
public static String getServerName(int node) {
|
|
|
|
ProxyServer proxyServer = ProxyServer.valueOf(node);
|
|
|
|
assert proxyServer != null;
|
|
|
|
return proxyServer.getServerName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取服务器IP地址
|
|
|
|
* @param serverName 服务器名称
|
|
|
|
*/
|
|
|
|
public static String getServerIP(String serverName) {
|
|
|
|
return serverIp.get(serverName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取服务器IP地址
|
|
|
|
* @param node 服务器标签
|
|
|
|
*/
|
|
|
|
public static String getServerIP(int node) {
|
|
|
|
return serverIp.get(getServerName(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取代理类型默认端口
|
|
|
|
* @param type 类型名称
|
|
|
|
*/
|
2022-04-06 17:49:00 +08:00
|
|
|
public static Integer getTypePort(String type) {
|
|
|
|
return typePort.get(type);
|
|
|
|
}
|
2022-04-09 03:59:20 +08:00
|
|
|
|
|
|
|
public static Integer getTypeIndex(String type) {
|
|
|
|
return Arrays.asList(ProxyType.values()).indexOf(ProxyType.valueOf(StringUtils.upperCase(type)));
|
|
|
|
}
|
2022-04-06 17:49:00 +08:00
|
|
|
}
|