Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/InetAddress/IsReachableViaLoopbackTest.java
47182 views
import java.io.*;1import java.net.*;2import java.util.*;34/**5* @test6* @bug 81353057* @summary ensure we can't ping external hosts via loopback if8*/910public class IsReachableViaLoopbackTest {11public static void main(String[] args) {12try {13InetAddress addr = InetAddress.getByName("localhost");14InetAddress remoteAddr = InetAddress.getByName("bugs.openjdk.java.net");15if (!addr.isReachable(10000))16throw new RuntimeException("Localhost should always be reachable");17NetworkInterface inf = NetworkInterface.getByInetAddress(addr);18if (inf != null) {19if (!addr.isReachable(inf, 20, 10000)) {20throw new RuntimeException("Localhost should always be reachable");21} else {22System.out.println(addr + " is reachable");23}24if (remoteAddr.isReachable(inf, 20, 10000)) {25throw new RuntimeException(remoteAddr + " is reachable");26} else {27System.out.println(remoteAddr + " is NOT reachable");28}29} else {30System.out.println("inf == null");31}3233} catch (IOException e) {34throw new RuntimeException("Unexpected exception:" + e);35}36System.out.println("IsReachableViaLoopbackTest EXIT");37}38}39404142