制作图形界面

This commit is contained in:
Administrator
2022-12-25 14:53:46 +08:00
parent 0797da8eb3
commit 6dd349e722
106 changed files with 13020 additions and 312 deletions
@@ -5,6 +5,8 @@ import java.io.BufferedOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.Socket;
@@ -12,7 +14,10 @@ import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;
@@ -23,19 +28,20 @@ import org.kne.cloud.network.mport.IPPort;
import org.kne.cloud.network.mport.ServiceElement;
import org.kne.cloud.network.mport.ThreadTool;
import com.google.gson.stream.JsonReader;
public class KLALBClient {
UUID suid=UUID.randomUUID();
IOThreadManager iom=new IOThreadManager();
private UUID suid=UUID.randomUUID();
private IOThreadManager iom=new IOThreadManager();
private List<Tunnel> tls=new ArrayList<>();
private TCPListener tcpl;
private ServiceElement sel;
private List<TCPListener> tcpl=new ArrayList<>();
public void open(int port) throws IOException {
tcpl=new TCPListener(port);
tcpl.setCon((s)->{
public void open(int port, ServiceElement sel,String bindip) throws IOException {
TCPListener tl=new TCPListener(port,bindip);
tl.setCon((s)->{
LocalTCPConnection tcc = null;
try {
tcc = new LocalTCPConnection(s);
@@ -51,7 +57,11 @@ public class KLALBClient {
}
}
});
tcpl.open();
tl.open();
tcpl.add(tl);
System.out.println(sel.name+"映射已启动 端口:"+port+" 绑定地址:"+bindip);
}
public void connectTunnel() {
for (int i = 0; i < tls.size(); i++) {
Tunnel tll=tls.get(i);
ThreadTool.makeVThreadIfSupport("隧道监视线程", ()->{
@@ -75,8 +85,10 @@ public class KLALBClient {
}
re=0;
System.out.println(tll+":连接成功");
tll.setState(true);
iom.handleRemote(tc);
System.out.println(tll+":连接断开");
tll.setState(false);
} catch (UnknownHostException e) {
e.printStackTrace();
}catch(ConnectException|SocketTimeoutException e) {
@@ -84,7 +96,7 @@ public class KLALBClient {
} catch (IOException e) {
e.printStackTrace();
}finally {
if(tc!=null)
if(tc!=null)
tc.close();
}
try {
@@ -105,92 +117,16 @@ public class KLALBClient {
public List<ServiceElement> getServices() {
return services;
}
public void searchTunnels(String ipport) throws IOException {
IPPort u=new IPPort(ipport);
TCPConnection tcpc=null;
try {
tcpc=new RemoteTCPConnection(null, new Socket(u.getIp(),u.getPort()));
tcpc.getDout().writeShort(59649);
tcpc.getDout().write(0);
tcpc.getDout().flush();
int s=tcpc.getDin().readInt();
System.out.println("服务列表:");
for (int i = 0; i < s; i++) {
String str=tcpc.getDin().readUTF();
System.out.println(str);
services.add(new ServiceElement(str));
}
int s2=tcpc.getDin().readInt();
System.out.println("隧道列表:");
for (int i = 0; i < s2; i++) {
String str=tcpc.getDin().readUTF();
System.out.println(str);
tls.add(Tunnel.newTunnel(str));
}
}finally {
if(tcpc!=null) {
tcpc.close();
}
public void close() {
iom.close();
for (Iterator<TCPListener> iterator = tcpl.iterator(); iterator.hasNext();) {
TCPListener tl = (TCPListener) iterator.next();
tl.close();
}
}
public ServiceElement getSel() {
return sel;
}
public void setSel(ServiceElement sel) {
this.sel = sel;
}
public static void main(String[] args) throws IOException {
Scanner scn=new Scanner(System.in);
KLALBClient kc=new KLALBClient();
/*File f=new File("klalbc.ini");
if(!f.exists()) {
f.createNewFile();
return;
}
Scanner scn=new scan*/
System.out.println("请输入服务器任意一条线路的地址:");
kc.searchTunnels(scn.next());//"153.36.240.12:65529"
System.out.println("你想要连接哪个服务?请输入序号:");
kc.setSel(kc.getServices().get(scn.nextInt()));
System.out.println("请输入你要映射的本地端口:");
kc.open(scn.nextInt());
System.out.println("服务已开启");
while(true) {
String s=scn.next();
switch(s) {
case "states":
Tunnel.states();
break;
}
}
}
//Tunnel t= new Tunnel("Test1", "127.0.0.1", 4569);
/*Tunnel t= new Tunnel("Test1", "cn-hz-bgp-1.openfrp.top", 65529);
tls.add(t);
Tunnel t2=new Tunnel("Test2","cn-bj-bgp-3.openfrp.top",65529);
tls.add(t2);
Tunnel t3=new Tunnel("Test3","180.76.147.250",65529);
tls.add(t3);
Tunnel t4=new Tunnel("Test4","cn-sx-xa-bgp-1.openfrp.top",65529);
tls.add(t4);
*/
/* List<Tunnel> tls=kc.getTls();
Tunnel t5=new Tunnel("Test5","la.afrps.cn",49966);
tls.add(t5);
Tunnel t6=new Tunnel("Test6","sg.afrps.cn",49966);
tls.add(t6);
Tunnel t7=new Tunnel("Test7","ch.afrps.cn",49966);
tls.add(t7);
Tunnel t8=new Tunnel("Test8","sj.afrps.cn",49966);
tls.add(t8);
Tunnel t9=new Tunnel("Test9","frp.104300.xyz",49965);
tls.add(t9);
Tunnel t11=new Tunnel("Test11","153.36.240.12",65529);
tls.add(t11);
Tunnel t12=new Tunnel("Test12","frp.freefrps.com",49965);
tls.add(t12);*/
}