68 lines
1.6 KiB
Java
68 lines
1.6 KiB
Java
package org.kne.cloud.network.nathole;
|
|
|
|
import java.io.IOException;
|
|
import java.net.InetAddress;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.ServerSocket;
|
|
import java.net.Socket;
|
|
import java.net.SocketTimeoutException;
|
|
import java.net.UnknownHostException;
|
|
|
|
public class TCPNatHoleTeat {
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
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();*/
|
|
}
|
|
}
|
|
}
|
|
}
|