Here you can find the source of pingFromInterface(String name)
public static boolean pingFromInterface(String name) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.*; import java.util.Enumeration; import static java.lang.System.out; public class Main { public static final String IPv6_ONLY_SERVER_IP = "2001::7"; public static final int IPv6_ONLY_SERVER_PORT = 22; public static boolean pingFromInterface(String name) throws IOException { out.println("Pinging from interface " + name); boolean connected = false; NetworkInterface networkInterface = NetworkInterface.getByName(name); if (networkInterface == null) { out.println("No network interface for " + name); return false; }/*from www . j a v a 2 s .co m*/ Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress localAddr = inetAddresses.nextElement(); out.println("Using address " + localAddr); connected |= pingFromLocalAddress(localAddr); } return connected; } public static boolean pingFromLocalAddress(InetAddress localAddr) throws IOException { boolean connected = false; Socket socket = null; try { socket = new Socket(IPv6_ONLY_SERVER_IP, IPv6_ONLY_SERVER_PORT, localAddr, 0); out.println("Created!"); connected = true; } catch (IOException e) { out.println("Failed to connect"); e.printStackTrace(out); } finally { if (socket != null) { socket.close(); } } return connected; } }