List of usage examples for org.apache.http.conn.util InetAddressUtils isIPv6Address
public static boolean isIPv6Address(final String input)
From source file:Main.java
static public boolean isValidIpAddress(String ip) { boolean v4 = InetAddressUtils.isIPv4Address(ip); boolean v6 = InetAddressUtils.isIPv6Address(ip); if (!v4 && !v6) return false; try {//from w w w . j a va 2 s . c om InetAddress inet = InetAddress.getByName(ip); return inet.isLinkLocalAddress() || inet.isSiteLocalAddress(); } catch (UnknownHostException e) { //Log.e(TAG, e.toString()); return false; } }
From source file:com.github.christiangda.utils.ip.IP.java
/** * @param ip String/*from w w w .j a v a2s . c o m*/ * @return boolean */ public static boolean isValidIP(String ip) { if (ip == null) { return false; } if (ip.isEmpty()) { return false; } return InetAddressUtils.isIPv4Address(ip) || InetAddressUtils.isIPv6Address(ip); }
From source file:io.github.lucaseasedup.logit.util.Validators.java
public static boolean validateIp(String ip) { if (StringUtils.isBlank(ip)) return false; return InetAddressUtils.isIPv4Address(ip) || InetAddressUtils.isIPv6Address(ip); }
From source file:com.github.christiangda.utils.ip.IP.java
/** * @param ip InetAddress//from w w w.ja v a2 s . c om * @return boolean */ public static boolean isValidIP(InetAddress ip) { return ip != null && (InetAddressUtils.isIPv4Address(ip.getHostAddress()) || InetAddressUtils.isIPv6Address(ip.getHostAddress())); }
From source file:com.github.christiangda.utils.ip.IP.java
/** * @param ip String/*from w ww .ja va 2 s . co m*/ * @return boolean */ public static boolean isValidIPV6(String ip) { if (ip == null) { return false; } if (ip.isEmpty()) { return false; } return InetAddressUtils.isIPv6Address(ip); }
From source file:com.github.christiangda.utils.ip.IP.java
/** * @param ip InetAddress/*from w ww .jav a 2 s. c o m*/ * @return boolean */ public static boolean isValidIPV6(InetAddress ip) { if (ip == null) { return false; } return InetAddressUtils.isIPv6Address(ip.getHostAddress()); }
From source file:com.vmware.identity.interop.ldap.DirectoryStoreProtocol.java
public URI getUri(String hostName, int port) { try {/*from w w w . java2 s . co m*/ return new URI(String.format("%s://%s:%d", this.name, InetAddressUtils.isIPv6Address(hostName) ? ("[" + hostName + "]") : hostName, port)); } catch (Exception e) { return null; } }
From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java
@Override public Socket createSocket(String host, int port) throws IOException { final String resolvedHost = resolver.resolve(host); if (resolvedHost != null && !resolvedHost.equals(host)) { if (InetAddressUtils.isIPv6Address(resolvedHost)) { final byte[] resolvedAddress = Inet6Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(host, resolvedAddress), port); } else if (InetAddressUtils.isIPv4Address(resolvedHost)) { final byte[] resolvedAddress = Inet4Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(host, resolvedAddress), port); }/*from w w w . j a v a 2s . c o m*/ } return defaultFactory.createSocket(host, port); }
From source file:io.ucoin.ucoinj.core.client.model.bma.gson.EndpointAdapter.java
@Override public NetworkPeering.Endpoint read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();// w w w .j av a 2 s . c o m return null; } String ept = reader.nextString(); ArrayList<String> parts = new ArrayList<>(Arrays.asList(ept.split(" "))); NetworkPeering.Endpoint endpoint = new NetworkPeering.Endpoint(); endpoint.port = Integer.parseInt(parts.remove(parts.size() - 1)); for (String word : parts) { if (InetAddressUtils.isIPv4Address(word)) { endpoint.ipv4 = word; } else if (InetAddressUtils.isIPv6Address(word)) { endpoint.ipv6 = word; } else if (word.startsWith("http")) { endpoint.url = word; } else { try { endpoint.protocol = EndpointProtocol.valueOf(word); } catch (IllegalArgumentException e) { // skip this part } } } if (endpoint.protocol == null) { endpoint.protocol = EndpointProtocol.UNDEFINED; } return endpoint; }
From source file:com.mashape.galileo.agent.common.IPAddressParserUtil.java
private static boolean isValidIp(final String ip) { String ipAdress = ip.toLowerCase().trim(); return InetAddressUtils.isIPv4Address(ipAdress) || InetAddressUtils.isIPv6Address(ipAdress); }