List of utility methods to do IP Address Get
String | getLocalIp() get Local Ip try { InetAddress localAddress = InetAddress.getLocalHost(); if (localAddress != null && !localAddress.isAnyLocalAddress() && !localAddress.isLoopbackAddress()) { return localAddress.getHostAddress(); } catch (Exception e1) { throw Throwables.propagate(e1); try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface current = interfaces.nextElement(); if (!current.isUp() || current.isLoopback() || current.isVirtual()) continue; Enumeration<InetAddress> addresses = current.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); if (addr.isLoopbackAddress()) continue; if (addr instanceof Inet4Address) { return addr.getHostAddress(); } catch (SocketException e) { throw Throwables.propagate(e); throw new RuntimeException("Cannot get local ip."); |
String | getLocalIP() get Local IP Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) { Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); for (InetAddress inetAddress : Collections.list(inetAddresses)) { if (inetAddress.isSiteLocalAddress()) { String inetAddressStr = inetAddress.toString(); while (inetAddressStr.startsWith("/")) inetAddressStr = inetAddressStr.substring(1); ... |
String | getLocalIP() get Local IP String localIP = "0.0.0.0"; try { localIP = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException uhe) { System.out.println("IP for the local host could not be found."); uhe.printStackTrace(); return localIP; ... |
String | getLocalIP() get Local IP try { InetAddress localHost = InetAddress.getLocalHost(); String hostAddress = localHost.getHostAddress(); return hostAddress; } catch (UnknownHostException e) { throw new RuntimeException(e); |
String | getLocalIP() get Local IP String ipOnly = ""; try { Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); if (nifs == null) return ""; while (nifs.hasMoreElements()) { NetworkInterface nif = nifs.nextElement(); if (!nif.isLoopback() && nif.isUp() && !nif.isVirtual()) { ... |
String | getLocalIp() get Local Ip String localIP; try { localIP = getLocalHost().getHostAddress(); } catch (Exception e) { localIP = "localhost"; return localIP; |
String | getLocalIp(final boolean useIpv6) get Local Ip try { final ArrayList<NetworkInterface> networkInterfaces = Collections .list(NetworkInterface.getNetworkInterfaces()); for (final NetworkInterface netInterface : networkInterfaces) { if (!netInterface.isLoopback() && !netInterface.isPointToPoint()) { final ArrayList<InetAddress> addresses = Collections.list(netInterface.getInetAddresses()); for (final InetAddress address : addresses) { if (address instanceof Inet4Address && !useIpv6) { ... |
String | getLocalIPAddress() Retrieve the IP address of the generation machine . try { InetAddress addr = InetAddress.getLocalHost(); byte[] ipAddr = addr.getAddress(); String ipAddrStr = ""; for (int i = 0; i < ipAddr.length; i++) { if (i > 0) { ipAddrStr += "."; ipAddrStr += ipAddr[i] & 0xFF; return ipAddrStr; } catch (UnknownHostException e) { return ""; |
String | getLocalIPAddress() get Local IP Address return checkIP(getIPFromAPI());
|
String | getLocalIPAddress() get Local IP Address String ipAddress = null; Enumeration<NetworkInterface> eIf = NetworkInterface.getNetworkInterfaces(); while (ipAddress == null && eIf.hasMoreElements()) { NetworkInterface nIf = eIf.nextElement(); Enumeration<InetAddress> eAddress = nIf.getInetAddresses(); while (eAddress.hasMoreElements()) { InetAddress address = eAddress.nextElement(); if (!address.isLoopbackAddress()) { ... |