List of utility methods to do Host Address Get
String | getHost(final String address) Returns host for the specified address. final URL url = getURL(address); return url != null ? url.getHost() : null; |
String | getHostAddress() Returns the textual presentation of the local host IP address. return java.net.InetAddress.getLocalHost().getHostAddress();
|
String | getHostAddress() get Host Address String strIP = ""; try { InetAddress thisIp = InetAddress.getLocalHost(); strIP = thisIp.getHostAddress(); } catch (Exception e) { e.printStackTrace(); strIP = ""; return strIP; |
String | getHostAddress() get Host Address try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException uhe) { throw new Error("Couldn't get this host address, which is needed to register in the database"); |
String | getHostAddress() get Host Address try { return (InetAddress.getLocalHost()).getHostAddress(); } catch (UnknownHostException uhe) { String host = uhe.getMessage(); if (host != null) { int colon = host.indexOf(':'); if (colon > 0) { return host.substring(0, colon); ... |
String | getHostAddress() Get the ip address of local host. DatagramSocket ds = new DatagramSocket(); ds.connect(InetAddress.getByName(DUMMY_OUT_IP), 80); InetAddress localAddress = ds.getLocalAddress(); if (localAddress.getHostAddress().equals("0.0.0.0")) { localAddress = InetAddress.getLocalHost(); return localAddress.getHostAddress(); |
String | getHostAddress() get Host Address final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { final NetworkInterface current = interfaces.nextElement(); if (!current.isUp() || current.isLoopback() || current.isVirtual()) { continue; final Enumeration<InetAddress> addresses = current.getInetAddresses(); while (addresses.hasMoreElements()) { ... |
short[] | getHostAddress() Gets the host address, works around byte[] getAddress() looking negative short[] address = new short[4]; try { InetAddress netAddress = InetAddress.getLocalHost(); String ipAddress = netAddress.getHostAddress(); int beginIndex = 0; int endIndex = ipAddress.indexOf('.'); address[0] = (short) Integer.parseInt(ipAddress.substring(beginIndex, endIndex)); beginIndex = endIndex + 1; ... |
String | getHostAddress() get Host Address List<String> addresses = new LinkedList<>(); Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface n = (NetworkInterface) interfaces.nextElement(); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); if (i instanceof Inet4Address) { ... |
InetAddress | getHostAddress() Get the host IP address Use env(IFACE) to select an interface or env(IP) to select a specific address to prefer IPv6 use: java.net.preferIPv6Stack=true boolean ipv6 = false; String pv4 = System.getProperty("java.net.preferIPv4Stack"); String pv6 = System.getProperty("java.net.preferIPv6Stack"); if (pv4 != null && pv4.equals("false")) { ipv6 = true; if (pv6 != null && pv6.equals("true")) { ipv6 = true; ... |