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