@Test(expected = SecurityException.class) public void testNotAllowedNetworkAccess() throws UnknownHostException { Inet4Address.getAllByName("www.google.com"); }
@Test public void testAllowedNetworkAccess() throws UnknownHostException { ArrayUtils.toString(Inet4Address.getAllByName("10.34.64.36")); }
@Override protected byte[] deriveIpAddress(final String hostName) throws UnknownHostException { final InetAddress[] addrs = Inet4Address.getAllByName(hostName); for (final InetAddress addr : addrs) { if (addr instanceof Inet4Address) { return addr.getAddress(); } } throw new UnknownHostException("InetAddress could not be found"); }
@Override protected byte[] deriveIpAddress(final String hostName) throws UnknownHostException { final InetAddress[] addrs = Inet4Address.getAllByName(hostName); for (final InetAddress addr : addrs) { if (addr instanceof Inet6Address) { return addr.getAddress(); } } throw new UnknownHostException("InetAddress could not be found"); }
@Test(groups = "dns") public void localhostAlias() throws UnknownHostException { assertThat(Inet4Address.getAllByName("localhost_alias")).isEqualTo(Inet4Address.getAllByName("localhost")); assertThat(Inet4Address.getAllByName("teradata_alias")).isEqualTo(Inet4Address.getAllByName("teradata.com")); } }
/** * Check if endpoint is accessible */ public static boolean resolvable(Endpoint endpoint) { for (int i = 0; i < 10; i++) { try { InetAddress[] addresses = Inet4Address.getAllByName(endpoint.getHost()); Thread.sleep(1000); return addresses.length > 0; } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (UnknownHostException ignore) { } } return false; }
@Override public InetSocketAddress resolve(String host, int port) throws UnknownHostException { InetAddress inetAddress = randomize( filter( Inet4Address.getAllByName( host ), Inet4Address.class ) ); if ( inetAddress == null ) { return null; } return new InetSocketAddress( inetAddress, port ); }