private static IPInfo getIPInfo() { try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress().toUpperCase(); boolean isIPv4 = isIPv4Address(sAddr); if (isIPv4) { IPInfo info = new IPInfo(); info.addr = addr; info.intf = intf; info.ip = sAddr; info.ip_hex = InetAddress_to_hex(addr); info.netmask_hex = netmask_to_hex(intf.getInterfaceAddresses().get(0).getNetworkPrefixLength()); return info; } } } } } catch (SocketException e) { e.printStackTrace(); } return null; }
private static IPInfo getIPInfo() { try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress().toUpperCase(); boolean isIPv4 = isIPv4Address(sAddr); if (isIPv4) { IPInfo info = new IPInfo(); info.addr = addr; info.intf = intf; info.ip = sAddr; info.ip_hex = InetAddress_to_hex(addr); info.netmask_hex = netmask_to_hex(intf.getInterfaceAddresses().get(0).getNetworkPrefixLength()); return info; } } } } } catch (SocketException e) { e.printStackTrace(); } return null; }
private static IPInfo getIPInfo() { try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress().toUpperCase(); boolean isIPv4 = isIPv4Address(sAddr); if (isIPv4) { IPInfo info = new IPInfo(); info.addr = addr; info.intf = intf; info.ip = sAddr; info.ip_hex = InetAddress_to_hex(addr); info.netmask_hex = netmask_to_hex(intf.getInterfaceAddresses().get(0).getNetworkPrefixLength()); return info; } } } } } catch (SocketException e) { e.printStackTrace(); } return null; }