Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathJavaTest.java
More file actions
Latest commit
42 lines (35 loc) · 1.07 KB
/
Copy pathJavaTest.java
File metadata and controls
42 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
importjava.net.InetAddress;
importjava.net.UnknownHostException;
importjava.nio.ByteBuffer;
importfr.free.miniupnp.libnatpmp.NatPmp;
importfr.free.miniupnp.libnatpmp.NatPmpResponse;
classJavaTest {
publicstaticvoidmain(String[] args) {
NatPmpnatpmp = newNatPmp();
natpmp.sendPublicAddressRequest();
NatPmpResponseresponse = newNatPmpResponse();
intresult = -1;
do{
result = natpmp.readNatPmpResponseOrRetry(response);
try {
Thread.sleep(4000);
} catch (InterruptedExceptione) {
//fallthrough
}
} while (result != 0);
byte[] bytes = intToByteArray(response.addr);
try {
InetAddressinetAddress = InetAddress.getByAddress(bytes);
System.out.println("Public address is " + inetAddress);
} catch (UnknownHostExceptione) {
thrownewRuntimeException(e);
}
}
publicstaticfinalbyte[] intToByteArray(intvalue) {
returnnewbyte[] {
(byte)value,
(byte)(value >>> 8),
(byte)(value >>> 16),
(byte)(value >>> 24)};
}
}