public static boolean isIPv6Address(final String input) { return isIPv6StdAddress(input) || isIPv6HexCompressedAddress(input); }
/** * Returns true if the provided address is an IPv6 address (or could be interpreted as one). This method is more * lenient than {@link InetAddressUtils#isIPv6Address(String)} because of different interpretations of IPv4-mapped * IPv6 addresses. * * See RFC 5952 Section 4 for more information on textual representation of the IPv6 addresses. * * @param address the address in text form * @return true if the address is or could be parsed as an IPv6 address */ static boolean isIPv6Address(String address) { // Note: InetAddressUtils#isIPv4MappedIPv64Address() fails on addresses that do not compress the leading 0:0:0... to :: // Expanded for debugging purposes boolean isNormalIPv6 = InetAddressUtils.isIPv6Address(address); // If the last two hextets are written in IPv4 form, treat it as an IPv6 address as well String everythingAfterLastColon = StringUtils.substringAfterLast(address, ":"); boolean isIPv4 = InetAddressUtils.isIPv4Address(everythingAfterLastColon); boolean isIPv4Mapped = InetAddressUtils.isIPv4MappedIPv64Address(everythingAfterLastColon); boolean isCompressable = address.contains("0:0") && !address.contains("::"); return isNormalIPv6 || isIPv4; }
public String GetIp(Boolean isV4) { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> ipAddr = intf.getInetAddresses(); ipAddr.hasMoreElements(); ) { InetAddress inetAddress = ipAddr.nextElement(); if(isV4) { // ipv4地址 if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) { return inetAddress.getHostAddress(); } }else{ // ipv6地址 if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv6Address(inetAddress.getHostAddress())) { return inetAddress.getHostAddress(); } } } } } catch (Exception ex) { // } return ""; }
if (InetAddressUtils.isIPv4Address(address.getHostAddress())) { log.debug(name + " ... has IPV4 addr " + address); if(checkForLocalhost && (!name.equalsIgnoreCase(Configuration.LOOP_BACK_INTERFACE) || !address.getHostAddress().equalsIgnoreCase(Configuration.LOOP_BACK_ADDRESS))) {
PublicSuffixList list = new PublicSuffixList(Arrays.asList(ADDITIONAL_TLDS), Collections.<String>emptyList()); try { in = new FileInputStream(geoFile); PublicSuffixList list2 = new PublicSuffixListParser().parse( new InputStreamReader(in, "UTF-8")); list = merge(list, list2); try { if (in != null) in.close(); } catch (IOException ioe) {} DEFAULT_MATCHER = new PublicSuffixMatcher(list.getRules(), list.getExceptions()); if (log.shouldWarn()) log.warn("Loaded " + geoFile + " in " + (System.currentTimeMillis() - begin) + " ms and created list with " + list.getRules().size() + " entries and " + list.getExceptions().size() + " exceptions"); } catch (IOException ex) { log.error("Failure loading public suffix list from " + geoFile, ex); list.addAll(Arrays.asList(DEFAULT_TLDS)); list.addAll(Arrays.asList(ADDITIONAL_TLDS)); DEFAULT_MATCHER = new PublicSuffixMatcher(list, null); if (log.shouldWarn()) log.warn("No public suffix list found at " + geoFile +
/** * @since 0.9.34 */ public static boolean isIPv6Address(String host) { return InetAddressUtils.isIPv6Address(host); }
/** * Merge two PublicSuffixLists * Have to do this because they are unmodifiable * * @since 0.9.20 */ private static PublicSuffixList merge(PublicSuffixList a, PublicSuffixList b) { List<String> ar = a.getRules(); List<String> ae = a.getExceptions(); List<String> br = b.getRules(); List<String> be = b.getExceptions(); List<String> cr = new ArrayList<String>(ar.size() + br.size()); List<String> ce = new ArrayList<String>(ae.size() + be.size()); cr.addAll(ar); cr.addAll(br); ce.addAll(ae); ce.addAll(be); return new PublicSuffixList(cr, ce); }
public boolean matches(final String domain) { if (domain == null) { return false; } final String domainRoot = getDomainRoot(domain.startsWith(".") ? domain.substring(1) : domain); return domainRoot == null; }
boolean more = true; while (more) { more = readLine(r, sb); String line = sb.toString(); if (line.isEmpty()) { return new PublicSuffixList(rules, exceptions);
/** * Checks whether the parameter is a valid IPv6 address (including compressed). * * @param input the address string to check for validity * @return true if the input parameter is a valid standard or compressed IPv6 address */ public static boolean isIPv6Address(final String input) { return isIPv6StdAddress(input) || isIPv6HexCompressedAddress(input); }
/** * @return true if either IPv4 or IPv6 * @since 0.9.34 */ public static boolean isIPAddress(String host) { return InetAddressUtils.isIPv4Address(host) || InetAddressUtils.isIPv6Address(host); }
cn.indexOf('.', 2) != -1 && acceptableCountryWildcard(cn) && !InetAddressUtils.isIPv4Address(host);
/** * Checks whether the parameter is a valid IPv6 address (including compressed). * * @param input the address string to check for validity * @return true if the input parameter is a valid standard or compressed IPv6 address */ public static boolean isIPv6Address(final String input) { return isIPv6StdAddress(input) || isIPv6HexCompressedAddress(input); }
final boolean strict) { if (publicSuffixMatcher != null && host.contains(".")) { if (!matchDomainRoot(host, publicSuffixMatcher.getDomainRoot(identity))) { return false;
public final void verify( final String host, final X509Certificate cert) throws SSLException { final boolean ipv4 = InetAddressUtils.isIPv4Address(host); final boolean ipv6 = InetAddressUtils.isIPv6Address(host); final int subjectType = ipv4 || ipv6 ? IP_ADDRESS_TYPE : DNS_NAME_TYPE; final List<String> subjectAlts = extractSubjectAlts(cert, subjectType); if (subjectAlts != null && !subjectAlts.isEmpty()) { if (ipv4) { matchIPAddress(host, subjectAlts); } else if (ipv6) { matchIPv6Address(host, subjectAlts); } else { matchDNSName(host, subjectAlts, this.publicSuffixMatcher); } } else { // CN matching has been deprecated by rfc2818 and can be used // as fallback only when no subjectAlts are available final X500Principal subjectPrincipal = cert.getSubjectX500Principal(); final String cn = extractCN(subjectPrincipal.getName(X500Principal.RFC2253)); if (cn == null) { throw new SSLException("Certificate subject for <" + host + "> doesn't contain " + "a common name and does not have alternative names"); } matchCN(host, cn, this.publicSuffixMatcher); } }
/** * @since 0.9.34 */ public static boolean isIPv4Address(String host) { return InetAddressUtils.isIPv4Address(host); }
/** * Checks whether the parameter is a valid IPv6 address (including compressed). * * @param input the address string to check for validity * @return true if the input parameter is a valid standard or compressed IPv6 address */ public static boolean isIPv6Address(final String input) { return isIPv6StdAddress(input) || isIPv6HexCompressedAddress(input); }
/** * Returns registrable part of the domain for the given domain name or {@code null} * if given domain represents a public suffix. * * @param domain * @return domain root */ public String getDomainRoot(final String domain) { return getDomainRoot(domain, null); }
InetAddress addr = addrs.nextElement(); log.debug(name + " ... has addr " + addr); if (InetAddressUtils.isIPv4Address(addr.getHostAddress())) { if(!useUpnpIface) { if(traceupnp)
InetAddress addr = addrs.nextElement(); log.debug(name + " ... has addr " + addr); if (InetAddressUtils.isIPv4Address(addr.getHostAddress())) { IPsPerNic++;