summaryrefslogtreecommitdiff
path: root/zto/ext/libnatpmp/JavaTest.java
diff options
context:
space:
mode:
authorJoseph Henry <[email protected]>2017-03-14 13:21:54 -0700
committerJoseph Henry <[email protected]>2017-03-14 13:21:54 -0700
commit695b8ecc55a4b54aa47df181c1cdb674fd4b512c (patch)
tree8b7815a5c2f4094d72cff5552d73dc7340277e3c /zto/ext/libnatpmp/JavaTest.java
parente800e47a6333a0b4fe7df2a6093716cb2b44d308 (diff)
upgraded core to 1.2.00.8.0
Diffstat (limited to 'zto/ext/libnatpmp/JavaTest.java')
-rw-r--r--zto/ext/libnatpmp/JavaTest.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/zto/ext/libnatpmp/JavaTest.java b/zto/ext/libnatpmp/JavaTest.java
new file mode 100644
index 0000000..0379c18
--- /dev/null
+++ b/zto/ext/libnatpmp/JavaTest.java
@@ -0,0 +1,42 @@
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import fr.free.miniupnp.libnatpmp.NatPmp;
+import fr.free.miniupnp.libnatpmp.NatPmpResponse;
+
+class JavaTest {
+ public static void main(String[] args) {
+ NatPmp natpmp = new NatPmp();
+
+ natpmp.sendPublicAddressRequest();
+ NatPmpResponse response = new NatPmpResponse();
+
+ int result = -1;
+ do{
+ result = natpmp.readNatPmpResponseOrRetry(response);
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ //fallthrough
+ }
+ } while (result != 0);
+
+ byte[] bytes = intToByteArray(response.addr);
+
+ try {
+ InetAddress inetAddress = InetAddress.getByAddress(bytes);
+ System.out.println("Public address is " + inetAddress);
+ } catch (UnknownHostException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static final byte[] intToByteArray(int value) {
+ return new byte[] {
+ (byte)value,
+ (byte)(value >>> 8),
+ (byte)(value >>> 16),
+ (byte)(value >>> 24)};
+ }
+}