Java InetAddress Ping pingFromLocalAddress(InetAddress localAddr)

Here you can find the source of pingFromLocalAddress(InetAddress localAddr)

Description

ping From Local Address

License

Open Source License

Declaration

public static boolean pingFromLocalAddress(InetAddress localAddr) throws IOException 

Method Source Code


//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;
    }
}

Related

  1. ping(InetAddress addr, NetworkInterface ni)
  2. ping(InetAddress host)
  3. ping(InetAddress target)
  4. pingUsingInetAddress()
  5. pingWindows(InetAddress address, long timeout)
  6. ping(final InetAddress address)