当前位置: 首页>>代码示例>>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;未经允许,请勿转载。