List of utility methods to do Local Address Get
List | getLocalInet4Address() get Local Inet Address ArrayList<InetAddress> ips = new ArrayList<>(); try { Enumeration<NetworkInterface> netIntf = NetworkInterface.getNetworkInterfaces(); while (netIntf.hasMoreElements()) { Enumeration<InetAddress> addresses = netIntf.nextElement().getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress ip = addresses.nextElement(); if (ip instanceof Inet4Address && ip.isSiteLocalAddress()) ... |
String | getLocalInternetProtocolAddress() get Local Internet Protocol Address Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { for (InterfaceAddress interfaceAddress : networkInterfaces.nextElement().getInterfaceAddresses()) { if (interfaceAddress.getAddress().isSiteLocalAddress()) { return interfaceAddress.getAddress().toString().replace("/", ""); throw new IllegalStateException("Expected the computer's local IP address but didn't get one!"); |
String | getLocalMachineAddress() get Local Machine Address try { String hostName = InetAddress.getLocalHost().getHostName(); InetAddress addrs[] = InetAddress.getAllByName(hostName); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress()) { return addr.getHostAddress(); return InetAddress.getLocalHost().getHostAddress(); } catch (Exception e) { return "Unknown"; |
InetAddress | getLocalNetAddress() get Local Net Address try { return getNet4Address(); } catch (Exception ex) { return null; |