List of utility methods to do IP Address Get
String | getExternalIPAddress() get External IP Address BufferedReader in = null; try { URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp"); in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); return in.readLine(); } catch (IOException ex) { } finally { try { ... |
String | getFirstLocalNonLoopbackIpAddress() get First Local Non Loopback Ip Address SortedSet<String> addresses = new TreeSet<String>(); Iterator<NetworkInterface> iterator = localInterfaces.iterator(); while (iterator.hasNext()) { NetworkInterface networkInterface = iterator.next(); Enumeration<InetAddress> inetAddressEnumeration = networkInterface.getInetAddresses(); while (inetAddressEnumeration.hasMoreElements()) { InetAddress address = inetAddressEnumeration.nextElement(); if (!address.isLoopbackAddress() && !address.getHostAddress().contains(":")) { ... |
InetAddress | getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6) Get the first non-loopback address. Enumeration en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface i = (NetworkInterface) en.nextElement(); for (Enumeration en2 = i.getInetAddresses(); en2.hasMoreElements();) { InetAddress addr = (InetAddress) en2.nextElement(); if (!addr.isLoopbackAddress()) { if (addr instanceof Inet4Address) { if (preferIPv6) { ... |
String | getFirstNonLoopBackAddress(boolean preferIpv4, boolean preferIPv6) get First Non Loop Back Address final Enumeration en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { final NetworkInterface i = (NetworkInterface) en.nextElement(); for (Enumeration en2 = i.getInetAddresses(); en2.hasMoreElements();) { final InetAddress address = (InetAddress) en2.nextElement(); if (!address.isLoopbackAddress()) { if (address instanceof Inet4Address) { if (preferIPv6) { ... |
String | getHostIp() get Host Ip if (null == getInetAddress()) { return null; String ip = getInetAddress().getHostAddress(); return ip; |
HashSet | getHostIP() get Host IP HashSet ipAdd = new HashSet(); try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() ... |
String | getHostIp() get Host Ip if (_hostIp == null) { try { if (System.getProperty("host.ip.forced") != null && !System.getProperty("host.ip.forced").equals("")) { _hostIp = System.getProperty("host.ip.forced"); } else { if (publicIPUnavilable()) { ... |
String | getHostIP() Find the IP address of localhost. try { byte[] ipAddr = InetAddress.getLocalHost().getAddress(); StringBuilder b = new StringBuilder(); if (ipAddr != null && ipAddr.length > 0) { b.append(ipAddr[0]); for (int i = 1; i < ipAddr.length; i++) { b.append('.').append(ipAddr[i]); return b.toString(); } catch (UnknownHostException e) { return null; |
String | getHostIP() Method to return the IP address of the host computer try { InetAddress thisIp = InetAddress.getLocalHost(); return thisIp.getHostAddress(); } catch (Exception e) { e.printStackTrace(); return "No IP Found"; |
String | getHostIpAddress() Returns the IP address hosting this JVM, or null if it could not be determined. try { InetAddress host = InetAddress.getLocalHost(); return host.getHostAddress(); } catch (Exception ex) { return null; |