69 lines
1.9 KiB
Java
69 lines
1.9 KiB
Java
package org.kne.cloud.network;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Scanner;
|
|
|
|
public class PortMultiUse {
|
|
public static HostPortMap services=new HostPortMap();
|
|
public static void main(String[] args) throws IOException {
|
|
File f=new File("ports.ini");
|
|
if(!f.exists()) {
|
|
f.createNewFile();
|
|
ept();
|
|
return;
|
|
}
|
|
if(f.length()<=0) {
|
|
ept();
|
|
return;
|
|
}
|
|
Scanner scn=new Scanner(f);
|
|
int remp=scn.nextInt();
|
|
System.out.println("端口复用程序V2.0");
|
|
System.out.println("开放端口:"+remp);
|
|
while(scn.hasNext() ) {
|
|
String s=scn.next();
|
|
System.out.println(s);
|
|
services.putN$H(s);
|
|
}
|
|
scn.close();
|
|
new PortRelay(remp,services).start();
|
|
System.out.println("提示:运行时输入reload可以重新加载配置文件,已经建立的TCP连接不受影响(暂不支持修改开放端口)");
|
|
Scanner scn2=new Scanner(System.in);
|
|
while(true) {
|
|
String command=scn2.next();
|
|
switch(command) {
|
|
case "reload":
|
|
synchronized (services) {
|
|
scn=new Scanner(f);
|
|
services.clear();
|
|
remp=scn.nextInt();
|
|
while(scn.hasNext() ) {
|
|
String s=scn.next();
|
|
System.out.println(s);
|
|
services.putN$H(s);
|
|
}
|
|
scn.close();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ept() {
|
|
System.out.println("请填写配置文件后再启动程序!");
|
|
System.out.println("格式:");
|
|
System.out.println("开放端口");
|
|
System.out.println("服务协议1$服务地址1$服务端口1");
|
|
System.out.println("服务协议2$服务地址2$服务端口2");
|
|
System.out.println("......");
|
|
System.out.println("服务协议n$服务地址n$服务端口n");
|
|
System.out.println("DEFAULT$默认服务地址$默认服务端口");
|
|
System.out.println("");
|
|
System.out.println("按照顺序从上向下匹配,若都不是则匹配最后一个");
|
|
}
|
|
|
|
}
|