KLALB完全大重写,代码规范了,可以当作网络库使用
This commit is contained in:
@@ -1,17 +1,51 @@
|
||||
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 {
|
||||
|
||||
x("183.198.152.240", 12187);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user