Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/InetAddress/IsReachableViaLoopbackTest.java
41149 views
1
import java.io.*;
2
import java.net.*;
3
import java.util.*;
4
5
/**
6
* @test
7
* @bug 8135305
8
* @key intermittent
9
* @summary ensure we can't ping external hosts via loopback if
10
*/
11
12
public class IsReachableViaLoopbackTest {
13
public static void main(String[] args) {
14
try {
15
InetAddress addr = InetAddress.getByName("localhost");
16
InetAddress remoteAddr = InetAddress.getByName("bugs.openjdk.java.net");
17
if (!addr.isReachable(10000))
18
throw new RuntimeException("Localhost should always be reachable");
19
NetworkInterface inf = NetworkInterface.getByInetAddress(addr);
20
if (inf != null) {
21
if (!addr.isReachable(inf, 20, 10000)) {
22
throw new RuntimeException("Localhost should always be reachable");
23
} else {
24
System.out.println(addr + " is reachable");
25
}
26
if (remoteAddr.isReachable(inf, 20, 10000)) {
27
throw new RuntimeException(remoteAddr + " is reachable");
28
} else {
29
System.out.println(remoteAddr + " is NOT reachable");
30
}
31
} else {
32
System.out.println("inf == null");
33
}
34
35
} catch (IOException e) {
36
throw new RuntimeException("Unexpected exception:" + e);
37
}
38
System.out.println("IsReachableViaLoopbackTest EXIT");
39
}
40
}
41
42
43