當前位置: 首頁>>代碼示例>>Java>>正文


Java InetAddresses.toAddrString方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:29,代碼來源:Helperfunctions.java

示例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));
}
 
開發者ID:opendaylight,項目名稱:netvirt,代碼行數:13,代碼來源:AclServiceUtils.java

示例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;
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:8,代碼來源:InetAddressAdapter.java

示例4: toString

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public String toString() {
  return InetAddresses.toAddrString(addr.getAddress()) + ':' +
      addr.getPort();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:6,代碼來源:IPCLoggerChannel.java

示例5: toString

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public String toString() {
    return InetAddresses.toAddrString(address);
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-pipeline-processor,代碼行數:5,代碼來源:IpAddress.java

示例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);
}
 
開發者ID:zhangjunfang,項目名稱:util,代碼行數:11,代碼來源:IPUtil.java


注:本文中的com.google.common.net.InetAddresses.toAddrString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。