List of utility methods to do Local Address Get
String | getLocalAddr() get Local Addr Enumeration<NetworkInterface> interfaces = null; try { interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface ifc = interfaces.nextElement(); if (ifc.isLoopback() || ifc.isVirtual() || !ifc.isUp()) { continue; Enumeration<InetAddress> addressesOfAnInterface = ifc.getInetAddresses(); while (addressesOfAnInterface.hasMoreElements()) { InetAddress address = addressesOfAnInterface.nextElement(); if (address.isSiteLocalAddress()) { return address.getHostAddress(); } catch (SocketException e) { e.printStackTrace(); return null; return null; |
InetAddress | getLocalAddr() Will try to find the local IP V4 address there is not the loopback address Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface dev = interfaces.nextElement(); String devName = dev.getDisplayName(); Enumeration<InetAddress> addresses = dev.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); if (addr instanceof Inet6Address) ... |
String | getLocalAddress() This method returns the local IP address as a String. try { return InetAddress.getLocalHost().getHostAddress(); } catch (Exception ex) { return "0.0.0.0"; |
InetAddress | getLocalAddress() get Local Address InetAddress addr = null; try { Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces(); InetAddress ip = null; while (netInterfaces.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement(); ip = (InetAddress) ni.getInetAddresses().nextElement(); if (!ip.isLoopbackAddress()) { ... |
String | getLocalAddress() Gets the local address. try { InetAddress localMachine = InetAddress.getLocalHost(); return localMachine.getHostAddress(); } catch (UnknownHostException uhe) { return ""; |
InetAddress | getLocalAddress() The preferred local address. NetworkInterface result_intf = null, intf; InetAddress result_addr = null, addr; Enumeration<InetAddress> eips = null; Enumeration<NetworkInterface> eintfs = null; try { eintfs = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { e1.printStackTrace(); ... |
InetAddress | getLocalAddress() get Local Address try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); ArrayList<Inet4Address> ipv4Result = new ArrayList<Inet4Address>(); ArrayList<Inet6Address> ipv6Result = new ArrayList<Inet6Address>(); while (enumeration.hasMoreElements()) { final NetworkInterface networkInterface = enumeration.nextElement(); final Enumeration<InetAddress> en = networkInterface.getInetAddresses(); while (en.hasMoreElements()) { ... |
InetAddress | getLocalAddress() get Local Address InetAddress addr = InetAddress.getLocalHost(); if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) { return addr; try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); if (interfaces != null) { while (interfaces.hasMoreElements()) { ... |
String | getLocalAddress() get Local Address return InetAddress.getLocalHost().getHostAddress();
|
InetAddress | getLocalAddress() get Local Address if (LOCAL_ADDRESS != null) return LOCAL_ADDRESS; InetAddress localAddress = getLocalAddress0(); LOCAL_ADDRESS = localAddress; return localAddress; |