@Override public InetAddress[] run() throws UnknownHostException { return InetAddress.getAllByName(hostname); } });
@Override public InetAddress[] run() throws UnknownHostException { return InetAddress.getAllByName(hostname); } });
@Override public InetAddress[] getAllByName(String name) throws UnknownHostException { return InetAddress.getAllByName(name); } });
@Override public InetAddress[] getAllByName(String name) throws UnknownHostException { return InetAddress.getAllByName(name); } });
@Override public InetAddress[] resolve(String host) throws UnknownHostException { return InetAddress.getAllByName(host); } }
/** * Get all addresses by host name. * * @param host Host name. * @return Addresses. * @throws UnknownHostException If host is unavailable. */ protected InetAddress[] getAllAddressesByHost(String host) throws UnknownHostException { return InetAddress.getAllByName(host); }
@Override public InetAddress[] run() throws UnknownHostException { return InetAddress.getAllByName(hostname); } });
@Override public InetAddress[] resolve(String host) throws UnknownHostException { return InetAddress.getAllByName(host); } },
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException { if (hostname == null) throw new UnknownHostException("hostname == null"); return Arrays.asList(InetAddress.getAllByName(hostname)); } };
public static List<String> resolve(String domainName) throws UnknownHostException { List<String> result = new ArrayList<String>(); InetAddress[] addresses = InetAddress.getAllByName(domainName); if (addresses != null) { for (InetAddress addr : addresses) { result.add(addr.getHostAddress()); } } return result; }
static List<InetAddress> resolve(String host, ClientDnsLookup clientDnsLookup) throws UnknownHostException { InetAddress[] addresses = InetAddress.getAllByName(host); if (ClientDnsLookup.USE_ALL_DNS_IPS == clientDnsLookup) { return filterPreferredAddresses(addresses); } else { return Collections.singletonList(addresses[0]); } }
private static boolean isLocalhostWithLoopbackIpAddress(String forAddress, final String ipAddress) { InetAddress[] allMatchingAddresses; try { allMatchingAddresses = InetAddress.getAllByName(forAddress); } catch (UnknownHostException e) { return false; } for (InetAddress inetAddress : allMatchingAddresses) { if (inetAddress.isLoopbackAddress() && inetAddress.getHostAddress().equals(ipAddress)) { return true; } } return false; }
public RemoteInput (int port, RemoteInputListener listener) { this.listener = listener; try { this.port = port; serverSocket = new ServerSocket(port); Thread thread = new Thread(this); thread.setDaemon(true); thread.start(); InetAddress[] allByName = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName()); ips = new String[allByName.length]; for (int i = 0; i < allByName.length; i++) { ips[i] = allByName[i].getHostAddress(); } } catch (Exception e) { throw new GdxRuntimeException("Couldn't open listening socket at port '" + port + "'", e); } }
public RemoteInput (int port, RemoteInputListener listener) { this.listener = listener; try { this.port = port; serverSocket = new ServerSocket(port); Thread thread = new Thread(this); thread.setDaemon(true); thread.start(); InetAddress[] allByName = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName()); ips = new String[allByName.length]; for (int i = 0; i < allByName.length; i++) { ips[i] = allByName[i].getHostAddress(); } } catch (Exception e) { throw new GdxRuntimeException("Couldn't open listening socket at port '" + port + "'", e); } }
public static boolean isLocalIpAddress(String ipAddress) { try { InetAddress[] allAddresses = InetAddress.getAllByName(ipAddress); boolean isLocal = false; for (InetAddress address : allAddresses) { isLocal = isLocal || address.isLoopbackAddress(); } return isLocal || isLocalhostWithNonLoopbackIpAddress(ipAddress); } catch (Exception e) { throw new RuntimeException(e); } }
//also, this fails for an invalid address, like "www.sjdosgoogle.com1234sd" InetAddress[] addresses = InetAddress.getAllByName("www.google.com"); for (InetAddress address : addresses) { if (address.isReachable(10000)) { System.out.println("Connected "+ address); } else { System.out.println("Failed "+address); } } //output:*Failed www.google.com/74.125.227.114*
protected static List<Address> resolveAEntries(String dnsQuery, String srcPort) { List<Address> addresses = new ArrayList<>(); try { InetAddress[] inetAddresses = InetAddress.getAllByName(dnsQuery); for (InetAddress address : inetAddresses) { addresses.add(new IpAddress(address, Integer.parseInt(srcPort))); } } catch (UnknownHostException ex) { log.trace("failed to resolve query %s, ex: %s", dnsQuery, ex.getMessage()); } return addresses; } }
/** * Checks whether we are running with java.net.preferIPv4Stack=true */ public void ensurePreferIPv4() throws IOException { InetAddress[] addrs = InetAddress.getAllByName("localhost"); for (InetAddress addr : addrs) { LOG.info("resolved localhost as:" + addr); Assert.assertEquals(4, addr.getAddress().length); //ensure 4 byte ipv4 address } }
private Socket connect() throws GeneralSecurityException, MessagingException, IOException { Exception connectException = null; InetAddress[] inetAddresses = InetAddress.getAllByName(settings.getHost()); for (InetAddress address : inetAddresses) { try { return connectToAddress(address); } catch (IOException e) { Timber.w(e, "Could not connect to %s", address); connectException = e; } } throw new MessagingException("Cannot connect to host", connectException); }
/** * Returns subject alternative names for "localhost". * @return the subject alternative names for "localhost". */ private static GeneralNames getLocalhostSubjectAltNames() throws UnknownHostException { InetAddress[] localAddresses = InetAddress.getAllByName("localhost"); GeneralName[] generalNames = new GeneralName[localAddresses.length + 1]; for (int i = 0; i < localAddresses.length; i++) { generalNames[i] = new GeneralName(GeneralName.iPAddress, new DEROctetString(localAddresses[i].getAddress())); } generalNames[generalNames.length - 1] = new GeneralName(GeneralName.dNSName, new DERIA5String("localhost")); return new GeneralNames(generalNames); }