本文整理汇总了Java中org.apache.http.conn.util.InetAddressUtils.isIPv6Address方法的典型用法代码示例。如果您正苦于以下问题:Java InetAddressUtils.isIPv6Address方法的具体用法?Java InetAddressUtils.isIPv6Address怎么用?Java InetAddressUtils.isIPv6Address使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.conn.util.InetAddressUtils
的用法示例。
在下文中一共展示了InetAddressUtils.isIPv6Address方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: domainMatch
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
static boolean domainMatch(final String domain, final String host) {
if (InetAddressUtils.isIPv4Address(host) || InetAddressUtils.isIPv6Address(host)) {
return false;
}
final String normalizedDomain = domain.startsWith(".") ? domain.substring(1) : domain;
if (host.endsWith(normalizedDomain)) {
final int prefix = host.length() - normalizedDomain.length();
// Either a full match or a prefix endidng with a '.'
if (prefix == 0) {
return true;
}
if (prefix > 1 && host.charAt(prefix - 1) == '.') {
return true;
}
}
return false;
}
示例2: checkField
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
public boolean checkField() {
if(!currencyBySpinner) {
//check address
String address = mAdress.getText().toString().trim();
if (!address.isEmpty()) {
if (!InetAddressUtils.isIPv4Address(address) &&
!InetAddressUtils.isIPv6Address(address) &&
!Patterns.WEB_URL.matcher(address).matches()) {
mAdress.setError(mContext.getString(R.string.invalid_peer_address));
return false;
}
}
//check port
if (mPort.getText().toString().trim().isEmpty()) {
mPort.setError(mContext.getString(R.string.port_cannot_be_empty));
return false;
} else if (Integer.parseInt(mPort.getText().toString()) <= 0 || 65535 <= Integer.parseInt(mPort.getText().toString())) {
mPort.setError(mContext.getString(R.string.invalid_peer_port));
return false;
}
}
return true;
}
示例3: verify
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
public 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);
}
}
示例4: verify
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
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);
}
}
示例5: buildString
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
private String buildString() {
StringBuilder sb = new StringBuilder();
if (this.scheme != null)
sb.append(this.scheme).append(':');
if (this.encodedSchemeSpecificPart != null)
sb.append(this.encodedSchemeSpecificPart);
else {
if (this.encodedAuthority != null)
sb.append("//").append(this.encodedAuthority);
else if (this.host != null) {
sb.append("//");
if (this.encodedUserInfo != null)
sb.append(this.encodedUserInfo).append("@");
else if (this.userInfo != null)
sb.append(encodeUserInfo(this.userInfo)).append("@");
if (InetAddressUtils.isIPv6Address(this.host))
sb.append("[").append(this.host).append("]");
else
sb.append(this.host);
if (this.port >= 0)
sb.append(":").append(this.port);
}
if (this.encodedPath != null)
sb.append(normalizePath(this.encodedPath));
else if (this.path != null)
sb.append(encodePath(normalizePath(this.path)));
if (this.encodedQuery != null)
sb.append("?").append(this.encodedQuery);
else if (this.queryParams != null)
sb.append("?").append(encodeQuery(this.queryParams));
}
if (this.encodedFragment != null)
sb.append("#").append(this.encodedFragment);
else if (this.fragment != null)
sb.append("#").append(encodeFragment(this.fragment));
return sb.toString();
}
示例6: verify
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
public void verify(
final String host, final X509Certificate cert) throws SSLException {
TYPE hostFormat = TYPE.DNS;
if (InetAddressUtils.isIPv4Address(host)) {
hostFormat = TYPE.IPv4;
} else {
String s = host;
if (s.startsWith("[") && s.endsWith("]")) {
s = host.substring(1, host.length() - 1);
}
if (InetAddressUtils.isIPv6Address(s)) {
hostFormat = TYPE.IPv6;
}
}
final int subjectType = hostFormat == TYPE.IPv4 || hostFormat == TYPE.IPv6 ? IP_ADDRESS_TYPE : DNS_NAME_TYPE;
final List<String> subjectAlts = extractSubjectAlts(cert, subjectType);
if (subjectAlts != null && !subjectAlts.isEmpty()) {
switch (hostFormat) {
case IPv4:
matchIPAddress(host, subjectAlts);
break;
case IPv6:
matchIPv6Address(host, subjectAlts);
break;
default:
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);
}
}
示例7: verify
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
@Override
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 ? DefaultHostnameVerifier.IP_ADDRESS_TYPE : DefaultHostnameVerifier.DNS_NAME_TYPE;
final List<String> subjectAlts = DefaultHostnameVerifier.extractSubjectAlts(cert, subjectType);
final X500Principal subjectPrincipal = cert.getSubjectX500Principal();
final String cn = DefaultHostnameVerifier.extractCN(subjectPrincipal.getName(X500Principal.RFC2253));
verify(host,
cn != null ? new String[] {cn} : null,
subjectAlts != null && !subjectAlts.isEmpty() ? subjectAlts.toArray(new String[subjectAlts.size()]) : null);
}
示例8: read
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
@Override
public Endpoint read(JsonReader reader) throws IOException {
if (reader.peek() == com.google.gson.stream.JsonToken.NULL) {
reader.nextNull();
return null;
}
String ept = reader.nextString();
ArrayList<String> parts = new ArrayList<>(Arrays.asList(ept.split(" ")));
Endpoint endpoint = new 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 (Patterns.WEB_URL.matcher(word).matches()) {
endpoint.url = word;
} else {
try {
endpoint.protocol = "BASIC_MERKLED_API";
} catch (IllegalArgumentException e) {
endpoint.protocol = "UNDEFINED";
}
}
}
return endpoint;
}
示例9: matches
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
private boolean matches(final String address) {
switch (this) {
case IPv4:
return InetAddressUtils.isIPv4Address(address);
case IPv6:
return InetAddressUtils.isIPv6Address(address);
default:
return false;
}
}
示例10: isValidIP
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
/**
* @param ip String
* @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);
}
示例11: isValidIPV6
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
/**
* @param ip String
* @return boolean
*/
public static boolean isValidIPV6(String ip) {
if (ip == null) {
return false;
}
if (ip.isEmpty()) {
return false;
}
return InetAddressUtils.isIPv6Address(ip);
}
示例12: isValidIpAddress
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
private boolean isValidIpAddress(String ip) {
boolean v4 = InetAddressUtils.isIPv4Address(ip);
boolean v6 = InetAddressUtils.isIPv6Address(ip);
if(!v4 && !v6) return false;
try {
InetAddress inet = InetAddress.getByName(ip);
return inet.isLinkLocalAddress() || inet.isSiteLocalAddress();
} catch(UnknownHostException e) {
Log.e(TAG, e.toString());
return false;
}
}
示例13: processIpAddress
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
private String processIpAddress(final Context context,
final Result proto,
final Map<String, Object> data,
final String key) {
Result ipres = new Result(proto);
ipres.addNode(key);
String address = (String) data.get(key);
if (address == null) {
ipres.setStatus(Result.Status.Failure);
ipres.setInfo("not present");
context.addResult(ipres);
} else {
ipres.setStatus(Result.Status.Success);
ipres.setInfo("present");
context.addResult(ipres);
Result ipvalid = new Result(proto);
ipvalid.addNode(key);
ipvalid.setStatus(Result.Status.Success);
ipvalid.setInfo("valid");
if (!(InetAddressUtils.isIPv4Address(address)
|| InetAddressUtils.isIPv6Address(address))) {
ipvalid.setStatus(Result.Status.Failure);
ipvalid.setInfo("invalid");
context.addResult(ipvalid);
} else {
ipvalid.setStatus(Result.Status.Success);
ipvalid.setInfo("valid");
context.addResult(ipvalid);
}
}
return address;
}
示例14: getHost
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
/**
* Returns the host to use when establishing the connection. The host and port to use
* might have been resolved by a DNS lookup as specified by the XMPP spec (and therefore
* may not match the {@link #getServiceName service name}.
*
* @return the host to use when establishing the connection.
*/
public String getHost() {
// 如果不是IP,则尝试将它以域名进行IP转换。
if(!InetAddressUtils.isIPv4Address(host) && !InetAddressUtils.isIPv6Address(host)) {
try {
InetAddress address = InetAddress.getByName(host);
host = address.getHostAddress();
Log.d(LOG_TAG, "transform host name to host address:"+host);
} catch (UnknownHostException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
}
return host;
}
示例15: getIP
import org.apache.http.conn.util.InetAddressUtils; //导入方法依赖的package包/类
public static String getIP(String input, PircBotX network, boolean IPv6Priority) {
String IP = "";
if (input.contains(".") || input.contains(":")) {
IP = input;
} else {
IP = IRCUtils.getHost(network, input);
}
if (InetAddressUtils.isIPv4Address(IP) || InetAddressUtils.isIPv6Address(IP)) {
return IP;
} else {
IP = IP.replaceAll("http://|https://", "");
try {
InetAddress[] addarray = InetAddress.getAllByName(IP);
String add = "";
if (IPv6Priority) {
for (InetAddress add6 : addarray) {
if (InetAddressUtils.isIPv6Address(add6.getHostAddress()))
add = add6.getHostAddress();
}
} else {
for (InetAddress add4 : addarray) {
if (InetAddressUtils.isIPv4Address(add4.getHostAddress()))
add = add4.getHostAddress();
}
}
if (add == null || add.isEmpty()) {
add = InetAddress.getByName(IP).getHostAddress();
}
return add;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}