Example usage for java.net NetworkInterface isPointToPoint

List of usage examples for java.net NetworkInterface isPointToPoint

Introduction

In this page you can find the example usage for java.net NetworkInterface isPointToPoint.

Prototype


public boolean isPointToPoint() throws SocketException 

Source Link

Document

Returns whether a network interface is a point to point interface.

Usage

From source file:eu.stratosphere.pact.test.util.minicluster.NepheleMiniCluster.java

private static NetworkInterface getNetworkInterface() throws SocketException {
    final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();

    while (interfaces.hasMoreElements()) {
        NetworkInterface nic = interfaces.nextElement();
        if (!nic.isLoopback() && !nic.isPointToPoint())
            return nic;
    }//from w ww  .j a v  a 2s .c  om

    throw new SocketException("Cannot find network interface which is not a loopback interface.");
}

From source file:org.pentaho.platform.util.UUIDUtil.java

public static String getActiveNetworkMacAddress() throws Exception {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface nif = interfaces.nextElement();
        // Obvious what the next IF is doing, but it must be connected, non-PPP, non-loopback, and non-virtual
        if ((nif.isUp()) && (!nif.isPointToPoint()) && (!nif.isLoopback()) && (!nif.isVirtual())) {
            return getInterfaceInfo(nif);
        }/*  w w  w .j  a v  a 2s .c  om*/
    }
    return null;
}

From source file:org.springframework.cloud.dataflow.yarn.streamappmaster.EmbeddedAppmasterTrackService.java

private static String getDefaultAddress() {
    Enumeration<NetworkInterface> nets;
    try {/*  w w w.ja v  a  2  s .c  o m*/
        nets = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        return null;
    }
    NetworkInterface netinf;
    while (nets.hasMoreElements()) {
        netinf = nets.nextElement();
        boolean skip = false;
        try {
            skip = netinf.isPointToPoint();
        } catch (SocketException e) {
            skip = true;
        }
        if (skip) {
            continue;
        }
        Enumeration<InetAddress> addresses = netinf.getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress address = addresses.nextElement();
            if (!address.isAnyLocalAddress() && !address.isMulticastAddress()
                    && !(address instanceof Inet6Address)) {
                return address.getHostAddress();
            }
        }
    }
    return null;
}

From source file:com.splout.db.common.GetIPAddresses.java

/**
 * Returns all available IP addresses./*from   w w w . j  a va2s  .  co m*/
 * <p/>
 * In error case or if no network connection is established, we return an empty list here.
 * <p/>
 * Loopback addresses are excluded - so 127.0.0.1 will not be never returned.
 * <p/>
 * The "primary" IP might not be the first one in the returned list.
 *
 * @return Returns all IP addresses (can be an empty list in error case or if network connection is missing).
 * @throws SocketException
 * @since 0.1.0
 */
public static Collection<InetAddress> getAllLocalIPs() throws SocketException {
    LinkedList<InetAddress> listAdr = new LinkedList<InetAddress>();

    Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
    if (nifs == null)
        return listAdr;

    while (nifs.hasMoreElements()) {
        NetworkInterface nif = nifs.nextElement();
        // We ignore subinterfaces - as not yet needed.
        Enumeration<InetAddress> adrs = nif.getInetAddresses();
        while (adrs.hasMoreElements()) {
            InetAddress adr = adrs.nextElement();
            if (adr != null && !adr.isLoopbackAddress()
                    && (nif.isPointToPoint() || !adr.isLinkLocalAddress())) {
                log.info("Available site local address: " + adr);
                listAdr.add(adr);
            }
        }
    }
    return listAdr;
}

From source file:Main.java

public static void printParameter(NetworkInterface ni) throws SocketException {
    System.out.println(" Name = " + ni.getName());
    System.out.println(" Display Name = " + ni.getDisplayName());
    System.out.println(" Is up = " + ni.isUp());
    System.out.println(" Support multicast = " + ni.supportsMulticast());
    System.out.println(" Is loopback = " + ni.isLoopback());
    System.out.println(" Is virtual = " + ni.isVirtual());
    System.out.println(" Is point to point = " + ni.isPointToPoint());
    System.out.println(" Hardware address = " + ni.getHardwareAddress());
    System.out.println(" MTU = " + ni.getMTU());

    System.out.println("\nList of Interface Addresses:");
    List<InterfaceAddress> list = ni.getInterfaceAddresses();
    Iterator<InterfaceAddress> it = list.iterator();

    while (it.hasNext()) {
        InterfaceAddress ia = it.next();
        System.out.println(" Address = " + ia.getAddress());
        System.out.println(" Broadcast = " + ia.getBroadcast());
        System.out.println(" Network prefix length = " + ia.getNetworkPrefixLength());
        System.out.println("");
    }//from w w w . jav  a  2  s  . c  om
}

From source file:net.straylightlabs.archivo.controller.TelemetryController.java

private static List<String> getNetworkInterfaces() {
    List<String> nics = new ArrayList<>();
    try {/*from   ww  w .j  a  v  a2 s . c om*/
        for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) {
            if (nic.isUp())
                nics.add(String.format(
                        "name='%s' isLoopback=%b isP2P=%b isVirtual=%b multicast=%b addresses=[%s]\n",
                        nic.getDisplayName(), nic.isLoopback(), nic.isPointToPoint(), nic.isVirtual(),
                        nic.supportsMulticast(), getAddressesAsString(nic)));
        }
    } catch (SocketException e) {
        logger.error("Error fetching network interface list: ", e);
    }
    return nics;
}

From source file:Main.java

private static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
    System.out.printf("Display name: %s%n", netint.getDisplayName());
    System.out.printf("Name: %s%n", netint.getName());
    Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
    for (InetAddress inetAddress : Collections.list(inetAddresses)) {
        System.out.printf("InetAddress: %s%n", inetAddress);
    }// w  w w . j  a va2s.com

    System.out.printf("Parent: %s%n", netint.getParent());
    System.out.printf("Up? %s%n", netint.isUp());
    System.out.printf("Loopback? %s%n", netint.isLoopback());
    System.out.printf("PointToPoint? %s%n", netint.isPointToPoint());
    System.out.printf("Supports multicast? %s%n", netint.isVirtual());
    System.out.printf("Virtual? %s%n", netint.isVirtual());
    System.out.printf("Hardware address: %s%n", Arrays.toString(netint.getHardwareAddress()));
    System.out.printf("MTU: %s%n", netint.getMTU());

    List<InterfaceAddress> interfaceAddresses = netint.getInterfaceAddresses();
    for (InterfaceAddress addr : interfaceAddresses) {
        System.out.printf("InterfaceAddress: %s%n", addr.getAddress());
    }
    System.out.printf("%n");
    Enumeration<NetworkInterface> subInterfaces = netint.getSubInterfaces();
    for (NetworkInterface networkInterface : Collections.list(subInterfaces)) {
        System.out.printf("%nSubInterface%n");
        displayInterfaceInformation(networkInterface);
    }
    System.out.printf("%n");
}

From source file:net.grinder.util.NetworkUtils.java

/**
 * Check if the current machine support IP6
 *
 * @return true if the IP6 is supported.
 *//*from  ww w  . j av a 2s. c  om*/
public static boolean isIP6Supported() {
    final Enumeration<NetworkInterface> networkInterfaces;
    try {
        networkInterfaces = getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            final NetworkInterface networkInterface = networkInterfaces.nextElement();
            if (networkInterface.isUp() && !networkInterface.isLoopback()
                    && !networkInterface.isPointToPoint()) {
                final Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    final InetAddress inetAddress = inetAddresses.nextElement();
                    if (inetAddress instanceof Inet6Address) {
                        return true;
                    }
                }
            }
        }
    } catch (SocketException e) {
        LOGGER.error("Error while resolving non look back local addresses.", e);
    }
    return false;

}

From source file:net.ftb.util.OSUtils.java

/**
 * Grabs the mac address of computer and makes it 10 times longer
 * @return a byte array containing mac address
 *//* ww w  .j  a va 2  s . co  m*/
public static byte[] getMacAddress() {
    if (cachedMacAddress != null && cachedMacAddress.length >= 10) {
        return cachedMacAddress;
    }
    try {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface network = networkInterfaces.nextElement();
            byte[] mac = network.getHardwareAddress();
            if (mac != null && mac.length > 0 && !network.isLoopback() && !network.isVirtual()
                    && !network.isPointToPoint() && network.getName().substring(0, 3) != "ham") {
                Logger.logDebug("Interface: " + network.getDisplayName() + " : " + network.getName());
                cachedMacAddress = new byte[mac.length * 10];
                for (int i = 0; i < cachedMacAddress.length; i++) {
                    cachedMacAddress[i] = mac[i - (Math.round(i / mac.length) * mac.length)];
                }
                return cachedMacAddress;
            }
        }
    } catch (SocketException e) {
        Logger.logWarn("Exception getting MAC address", e);
    }

    Logger.logWarn("Failed to get MAC address, using default logindata key");
    return new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
}

From source file:com.distrimind.madkit.kernel.MadkitProperties.java

private static long getMacAddress() {
    long result = 0;
    long result2 = 0;
    try {/*from  ww w. j av  a  2  s  .c o m*/
        final Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
        while (e.hasMoreElements()) {
            final NetworkInterface ni = e.nextElement();

            if (!ni.isLoopback()) {

                long val = getHardwareAddress(ni.getHardwareAddress());
                if (val != 0 && val != 224) {
                    if (ni.isPointToPoint()) {
                        result2 = val;
                    } else {
                        result = val;
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (result == 0)
        result = result2;
    return result;

}