Java Network Interface Get isNixMashPC()

Here you can find the source of isNixMashPC()

Description

is Nix Mash PC

License

Open Source License

Declaration

public static boolean isNixMashPC() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.NetworkInterface;
import java.net.SocketException;

import java.util.Enumeration;

public class Main {
    public static boolean isNixMashPC() {
        boolean isNixMashPC = false;
        try {//from  www . ja  v  a 2 s .  c o  m
            for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
                NetworkInterface ni = e.nextElement();
                if (ni.getDisplayName().equals("wlp5s0"))
                    isNixMashPC = formatMac(ni.getHardwareAddress()).equals("10-FE-ED-84-9E-A9");
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        return isNixMashPC;
    }

    private static String formatMac(byte[] mac) {
        if (mac == null)
            return "UNKNOWN";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < mac.length; i++) {
            sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
        }
        return sb.toString();
    }
}

Related

  1. getNonLoopbackLocalAdresses()
  2. getNonLoopbackNetworkInterface()
  3. getPublicInterface()
  4. getUsualNetworkInterfaces()
  5. isActive(String niName)
  6. parseInterfaceList(String s)
  7. pingFromInterface(String name)
  8. print(Collection objs)
  9. printValidInterfaces(PrintWriter pout)