List of utility methods to do Network Interface Get
int | getLinkLocalScopeId() get Link Local Scope Id for (InetAddress a : getIPAddresses()) { if (a instanceof Inet6Address && a.isLinkLocalAddress()) { return ((Inet6Address) a).getScopeId(); throw new IOException("No IPv6 support on this device"); |
Enumeration | getLocalInterfaces() Return the set of network interfaces for the local host. return NetworkInterface.getNetworkInterfaces();
|
String | getLocalMac() get Local Mac try { NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()); byte[] mac = network.getHardwareAddress(); StringBuilder sb = new StringBuilder(); for (int i = 0, ci = mac.length; i < ci; i++) { sb.append(String.format("%02X%s", mac[i], (i < ci - 1) ? "-" : "")); return sb.toString(); ... |
NetworkInterface | getLocalNetworkInterface() get Local Network Interface Enumeration<NetworkInterface> interfaces; try { interfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { throw new RuntimeException("NetworkInterface not found", e); while (interfaces.hasMoreElements()) { NetworkInterface networkInterface = interfaces.nextElement(); ... |
String | getLoopbackInterface() get Loopback Interface String networkInterface = ""; try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface resolvedNetworkInterface = interfaces.nextElement(); if (resolvedNetworkInterface.isLoopback()) { networkInterface = resolvedNetworkInterface.getDisplayName(); break; ... |
String | getLoopbackInterfaceName() Get the loopback interface name. try { for (NetworkInterface netIf : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (netIf == null) { continue; if (netIf.isLoopback()) { return netIf.getName(); } catch (SocketException ex) { return null; |
NetworkInterface | getLoopbackNIF() Get a loopback NIF. Enumeration<NetworkInterface> nets; try { nets = NetworkInterface.getNetworkInterfaces(); } catch (SocketException se) { return null; while (nets.hasMoreElements()) { NetworkInterface net = nets.nextElement(); ... |
String | getMac() get Mac StringBuilder builder = new StringBuilder(); try { Enumeration<NetworkInterface> el = NetworkInterface.getNetworkInterfaces(); while (el.hasMoreElements()) { byte[] mac = el.nextElement().getHardwareAddress(); StringBuilder subBuilder = new StringBuilder(); if (mac == null) continue; ... |
byte[] | getMacBytes() get Mac Bytes try { InetAddress ia = InetAddress.getLocalHost(); return NetworkInterface.getByInetAddress(ia).getHardwareAddress(); } catch (Exception e) { return null; |
String | getNetworkErrorMessage(Throwable e) get Network Error Message if ("InvalidProtocolBufferException".equals(e.getClass().getSimpleName())) { return "Your Internet provider may require you to log in via your web browser."; if (e instanceof UnknownHostException) { return "You may not be connected to the Internet."; } else { return e.getClass().getSimpleName() + ": " + e.getMessage(); |