List of utility methods to do Local Address Get
String | getLocalAddress() get Local Address try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { try { return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e1) { return "localhost"; |
String | getLocalAddress() get Local Address try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); ArrayList<String> ipv4Result = new ArrayList<String>(); ArrayList<String> ipv6Result = new ArrayList<String>(); while (enumeration.hasMoreElements()) { final NetworkInterface networkInterface = enumeration.nextElement(); final Enumeration<InetAddress> en = networkInterface.getInetAddresses(); while (en.hasMoreElements()) { ... |
String | getLocalAddress() get Local Address String addr = null; try { InetAddress ia = InetAddress.getLocalHost(); if (ia != null) addr = ia.getHostAddress(); } catch (UnknownHostException uhe) { return addr; ... |
String | getLocalAddress(final String start, final String end) get Local Address return start + "localhost:" + getNextAvailablePort() + end; |
InetSocketAddress | getLocalAddress(int port) get Local Address String hostInfo = null; try { hostInfo = InetAddress.getLocalHost().getHostName(); InetAddress.getByName(hostInfo); return new InetSocketAddress(hostInfo, port); } catch (UnknownHostException e) { return new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port); ... |
InetSocketAddress | getLocalAddress(int port) get Local Address String ipAddress = InetAddress.getLocalHost().getHostAddress(); return new InetSocketAddress(ipAddress, port); |
URL | getLocalAddress(int port) get Local Address try { return new URI("http://localhost:" + port).toURL(); } catch (URISyntaxException | MalformedURLException e) { throw new RuntimeException(e); |
InetAddress | getLocalAddress(String adaptorName) get Local Address try { Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces(); while (b.hasMoreElements()) { NetworkInterface networkInterface = b.nextElement(); if (networkInterface.getName().equals(adaptorName)) { for (InterfaceAddress f : networkInterface.getInterfaceAddresses()) { if (f.getAddress().isSiteLocalAddress()) { return f.getAddress(); ... |
String | getLocalAddress(String filter) get Local Address if (filter == null) { InetAddress addr; try { addr = InetAddress.getLocalHost(); return addr.getHostAddress().toString(); } catch (UnknownHostException e) { throw new RuntimeException("Failed to getLocalAddress", e); Pattern filterPattern = Pattern.compile(filter); try { Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces(); while (networks.hasMoreElements()) { NetworkInterface network = networks.nextElement(); Enumeration<InetAddress> addresses = network.getInetAddresses(); while (addresses.hasMoreElements()) { String address = addresses.nextElement().getHostAddress(); Matcher m = filterPattern.matcher(address); if (m.matches()) { return address; } catch (SocketException e) { throw new RuntimeException("Failed to getLocalAddress", e); throw new RuntimeException("Failed to getLocalAddress"); |
InetAddress | getLocalAddress0() get Local Address InetAddress localAddress = null; try { localAddress = InetAddress.getLocalHost(); if (isValidAddress(localAddress)) { return localAddress; } catch (Exception e) { e.printStackTrace(); ... |