Example usage for java.net InetAddress isMCNodeLocal

List of usage examples for java.net InetAddress isMCNodeLocal

Introduction

In this page you can find the example usage for java.net InetAddress isMCNodeLocal.

Prototype

public boolean isMCNodeLocal() 

Source Link

Document

Utility routine to check if the multicast address has node scope.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress address = InetAddress.getByName("web.mit.edu");
    System.out.println("Name: " + address.getHostName());
    System.out.println("Addr: " + address.getHostAddress());
    System.out.println(address.isMCNodeLocal());
}

From source file:org.blue.star.plugins.check_ping.java

public boolean execute_check() {

    for (String hostname : addresses) {

        try {//from w ww .  j  av a  2  s. c o m

            InetAddress inet = InetAddress.getByName(hostname);

            long execute_time = 0;
            long packet_loss = 0;
            for (int pings = 0; pings < max_packets; pings++) {
                boolean reachable = false;
                long ping_time = System.currentTimeMillis();
                if (network_interface != null) {
                    reachable = inet.isReachable(network_interface, 0, utils_h.timeout_interval);
                } else {
                    reachable = inet.isReachable(utils_h.timeout_interval);
                }
                execute_time += (System.currentTimeMillis() - ping_time);
                if (!reachable)
                    packet_loss++;
            }
            rta = execute_time / max_packets;
            pl = (int) packet_loss / max_packets * 100;

            if (verbose > 0) {
                System.out.println("rta = " + rta);
                System.out.println("pl = " + pl);
            }

            if (verbose > 1) {
                System.out.println("isAnyLocalAddress = " + inet.isAnyLocalAddress());
                System.out.println("isLinkLocalAddress = " + inet.isLinkLocalAddress());
                System.out.println("isLoopbackAddress = " + inet.isLoopbackAddress());
                System.out.println("isMCGlobal = " + inet.isMCGlobal());
                System.out.println("isMCLinkLocal = " + inet.isMCLinkLocal());
                System.out.println("isMCNodeLocal = " + inet.isMCNodeLocal());
                System.out.println("isMCOrgLocal = " + inet.isMCOrgLocal());
                System.out.println("isMCSiteLocal = " + inet.isMCSiteLocal());
                System.out.println("isMulticastAddress = " + inet.isMulticastAddress());
                System.out.println("isSiteLocalAddress = " + inet.isSiteLocalAddress());
                System.out.println("isReachable = " + inet.isReachable(utils_h.timeout_interval));
                System.out.println("getCanonicalHostName = " + inet.getCanonicalHostName());
                System.out.println("getHostAddress = " + inet.getHostAddress());
                System.out.println("getHostName = " + inet.getHostName());
                System.out.println("getClass.getName = " + inet.getClass().getName());
            }

            /* The list is only used to check alternatives, if we pass don't do more */
            if (packet_loss != max_packets)
                break;

        } catch (Exception e) {
            warn_text = e.getMessage();
            e.printStackTrace();
        }

    }

    if (pl >= cpl || rta >= crta || rta < 0)
        check_state = common_h.STATE_CRITICAL;
    else if (pl >= wpl || rta >= wrta)
        check_state = common_h.STATE_WARNING;
    else if (pl >= 0 && rta >= 0)
        check_state = common_h.STATE_OK;

    return true;
}