Here you can find the source of pingFromLocalAddress(InetAddress localAddr)
public static boolean pingFromLocalAddress(InetAddress localAddr) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.*; 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 pingFromLocalAddress(InetAddress localAddr) throws IOException { boolean connected = false; Socket socket = null;//from w w w . j av a 2 s. c o m 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; } }