KLALB大更新

新负载均衡算法
This commit is contained in:
Administrator
2023-07-02 13:20:11 +08:00
parent f743b23e53
commit 585b7c5fe6
59 changed files with 1681 additions and 553 deletions
@@ -1,101 +0,0 @@
package org.kne.cloud.network.nathole;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketImpl;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Arrays;
public class TCPNatHoleTeat {
public static void main(String[] args) throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
ServerSocket ssk=new ServerSocket(8089);
Field si= ssk.getClass().getDeclaredField("impl");
si.setAccessible(true);
SocketImpl sii= (SocketImpl) si.get(ssk);
Method sim= sii.getClass().getDeclaredMethod("connect", SocketAddress.class,int.class);
sim.setAccessible(true);
new Thread(()->{
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
while(true) {
try {
sim.invoke(sii, new InetSocketAddress(InetAddress.getByName("3.3.3.3"), 56) ,1);
} catch (IllegalAccessException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (InvocationTargetException e) {
} catch (UnknownHostException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}).start();
ssk.accept();
//x("183.198.152.240", 12187);
}
private static void x(String nat, int port) throws IOException {
for (int i = 10000; i < 20000; i++) {
System.out.println("try" + i);
Socket s = null;
ServerSocket srs = null;
try {
s = new Socket();
s.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), i));
try {
s.connect(new InetSocketAddress(InetAddress.getByName("1.1.1.1"), 443), 1);
}catch(SocketTimeoutException e) {
}
s.close();
srs = new ServerSocket();
srs.setReuseAddress(true);
srs.bind(new InetSocketAddress("0.0.0.0", i));
ServerSocket srs2 = srs;
new Thread(() -> {
try {
while (true) {
Socket sa = srs2.accept();
System.out.println(sa.toString());
//sa.close();
// System.exit(0);
}
} catch (IOException e) {
// e.printStackTrace();
}
}).start();
/*Socket ste = new Socket();
try {
ste.connect(new InetSocketAddress(nat, port), 1);
} catch (SocketTimeoutException e) {
}
ste.close();*/
} catch (IOException e) {
e.printStackTrace();
} finally {
if (s != null)
s.close();
/*if (srs != null)
srs.close();*/
}
}
}
}