本文整理匯總了Java中com.google.common.net.InetAddresses.toAddrString方法的典型用法代碼示例。如果您正苦於以下問題:Java InetAddresses.toAddrString方法的具體用法?Java InetAddresses.toAddrString怎麽用?Java InetAddresses.toAddrString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.net.InetAddresses
的用法示例。
在下文中一共展示了InetAddresses.toAddrString方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: anonymizeIp
import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
* Anonymize an IP address
* @param inetAddress the IP address to be anonymized
* @param replaceLastOctetWith the String which shall replace the last octet in IPv4
* @return
*/
public static String anonymizeIp(final InetAddress inetAddress, String replaceLastOctetWith) {
try
{
final byte[] address = inetAddress.getAddress();
address[address.length - 1] = 0;
if (address.length > 4) // ipv6
{
for (int i = 6; i < address.length; i++)
address[i] = 0;
}
String result = InetAddresses.toAddrString(InetAddress.getByAddress(address));
if (address.length == 4)
result = result.replaceFirst(".0$", replaceLastOctetWith);
return result;
}
catch (final Exception e)
{
e.printStackTrace();
return null;
}
}
示例2: getBroadcastAddressFromCidr
import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
public static String getBroadcastAddressFromCidr(String cidr) {
String[] ipaddressValues = cidr.split("/");
int address = InetAddresses.coerceToInteger(InetAddresses.forString(ipaddressValues[0]));
int cidrPart = Integer.parseInt(ipaddressValues[1]);
int netmask = 0;
for (int j = 0; j < cidrPart; ++j) {
netmask |= 1 << 31 - j;
}
int network = address & netmask;
int broadcast = network | ~netmask;
return InetAddresses.toAddrString(InetAddresses.fromInteger(broadcast));
}
示例3: marshal
import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public AddressShim marshal(InetAddress inetAddress) {
AddressShim shim = new AddressShim();
shim.ipAddress = InetAddresses.toAddrString(inetAddress);
shim.ipVersion = (inetAddress instanceof Inet6Address) ? "v6" : "v4";
return shim;
}
示例4: toString
import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public String toString() {
return InetAddresses.toAddrString(addr.getAddress()) + ':' +
addr.getPort();
}
示例5: toString
import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public String toString() {
return InetAddresses.toAddrString(address);
}
示例6: toString
import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
* InetAddress轉換為String.
*
* InetAddress可以是IPV4或IPV6. 其中IPV4直接調用getHostAddress()
*
* @see com.google.common.net.InetAddresses#toAddrString(InetAddress)
*/
public static String toString(InetAddress address) {
return InetAddresses.toAddrString(address);
}