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