本文整理汇总了Java中sun.net.util.IPAddressUtil.textToNumericFormatV4方法的典型用法代码示例。如果您正苦于以下问题:Java IPAddressUtil.textToNumericFormatV4方法的具体用法?Java IPAddressUtil.textToNumericFormatV4怎么用?Java IPAddressUtil.textToNumericFormatV4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.net.util.IPAddressUtil
的用法示例。
在下文中一共展示了IPAddressUtil.textToNumericFormatV4方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAddressByteArray
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
private byte [] createAddressByteArray(String addrStr) {
byte[] addrArray;
// check if IPV4 address - most likely
addrArray = IPAddressUtil.textToNumericFormatV4(addrStr);
if (addrArray == null) {
addrArray = IPAddressUtil.textToNumericFormatV6(addrStr);
}
return addrArray;
}
示例2: getServerName
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* If the address was created with a domain name, then return
* the domain name string. If created with a literal IP address
* then return null. We do this to avoid doing a reverse lookup
* Used to populate the TLS SNI parameter. So, SNI is only set
* when a domain name was supplied.
*/
public static String getServerName(InetSocketAddress addr) {
String host = addr.getHostString();
if (IPAddressUtil.textToNumericFormatV4(host) != null)
return null;
if (IPAddressUtil.textToNumericFormatV6(host) != null)
return null;
return host;
}
示例3: intOfIpV4
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
public int intOfIpV4(String ip) {
int result = 0;
byte[] bytes = IPAddressUtil.textToNumericFormatV4(ip);
if (bytes == null) {
return result;
}
for (byte b : bytes) {
result = result << 8 | (b & 0xFF);
}
return result;
}
示例4: ip2ByteArray
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* dig from InetAddress#getAllByName(java.lang.String, java.net.InetAddress)
*/
static byte[] ip2ByteArray(String ip) {
boolean ipv6Expected = false;
if (ip.charAt(0) == '[') {
// This is supposed to be an IPv6 literal
if (ip.length() > 2 && ip.charAt(ip.length() - 1) == ']') {
ip = ip.substring(1, ip.length() - 1);
ipv6Expected = true;
} else {
// This was supposed to be a IPv6 address, but it's not!
throw new IllegalArgumentException(ip + ": invalid IPv6 address");
}
}
if (Character.digit(ip.charAt(0), 16) != -1 || (ip.charAt(0) == ':')) {
// see if it is IPv4 address
byte[] address = IPAddressUtil.textToNumericFormatV4(ip);
if (address != null) return address;
// see if it is IPv6 address
// Check if a numeric or string zone id is present
address = IPAddressUtil.textToNumericFormatV6(ip);
if (address != null) return address;
if (ipv6Expected) {
throw new IllegalArgumentException(ip + ": invalid IPv6 address");
} else {
throw new IllegalArgumentException(ip + ": invalid IP address");
}
} else {
throw new IllegalArgumentException(ip + ": invalid IP address");
}
}
示例5: internalIp
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**判断IP是否为内网IP*/
public static boolean internalIp(String ip) {
byte[] addr = IPAddressUtil.textToNumericFormatV4(ip);
return internalIp(addr);
}