当前位置: 首页>>代码示例>>Java>>正文


Java InetAddresses.isInetAddress方法代码示例

本文整理汇总了Java中com.google.common.net.InetAddresses.isInetAddress方法的典型用法代码示例。如果您正苦于以下问题:Java InetAddresses.isInetAddress方法的具体用法?Java InetAddresses.isInetAddress怎么用?Java InetAddresses.isInetAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.net.InetAddresses的用法示例。


在下文中一共展示了InetAddresses.isInetAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocalInterfaceAddrs

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
 * Return the socket addresses to use with each configured
 * local interface. Local interfaces may be specified by IP
 * address, IP address range using CIDR notation, interface
 * name (e.g. eth0) or sub-interface name (e.g. eth0:0).
 * The socket addresses consist of the IPs for the interfaces
 * and the ephemeral port (port 0). If an IP, IP range, or
 * interface name matches an interface with sub-interfaces
 * only the IP of the interface is used. Sub-interfaces can
 * be used by specifying them explicitly (by IP or name).
 *
 * @return SocketAddresses for the configured local interfaces,
 *    or an empty array if none are configured
 * @throws UnknownHostException if a given interface name is invalid
 */
private static SocketAddress[] getLocalInterfaceAddrs(
    String interfaceNames[]) throws UnknownHostException {
  List<SocketAddress> localAddrs = new ArrayList<>();
  for (String interfaceName : interfaceNames) {
    if (InetAddresses.isInetAddress(interfaceName)) {
      localAddrs.add(new InetSocketAddress(interfaceName, 0));
    } else if (NetUtils.isValidSubnet(interfaceName)) {
      for (InetAddress addr : NetUtils.getIPs(interfaceName, false)) {
        localAddrs.add(new InetSocketAddress(addr, 0));
      }
    } else {
      for (String ip : DNS.getIPs(interfaceName, false)) {
        localAddrs.add(new InetSocketAddress(ip, 0));
      }
    }
  }
  return localAddrs.toArray(new SocketAddress[localAddrs.size()]);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:34,代码来源:NuCypherExtClient.java

示例2: ipToLong

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
public static long ipToLong(String ip) {
    try {
        if (!InetAddresses.isInetAddress(ip)) {
            throw new IllegalArgumentException("failed to parse ip [" + ip + "], not a valid ip address");
        }
        String[] octets = pattern.split(ip);
        if (octets.length != 4) {
            throw new IllegalArgumentException("failed to parse ip [" + ip + "], not a valid ipv4 address (4 dots)");
        }
        return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16) +
                (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]);
    } catch (Exception e) {
        if (e instanceof IllegalArgumentException) {
            throw (IllegalArgumentException) e;
        }
        throw new IllegalArgumentException("failed to parse ip [" + ip + "]", e);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:IpFieldMapper.java

示例3: getLocalInterfaceAddrs

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
 * Return the socket addresses to use with each configured
 * local interface. Local interfaces may be specified by IP
 * address, IP address range using CIDR notation, interface
 * name (e.g. eth0) or sub-interface name (e.g. eth0:0).
 * The socket addresses consist of the IPs for the interfaces
 * and the ephemeral port (port 0). If an IP, IP range, or
 * interface name matches an interface with sub-interfaces
 * only the IP of the interface is used. Sub-interfaces can
 * be used by specifying them explicitly (by IP or name).
 * 
 * @return SocketAddresses for the configured local interfaces,
 *    or an empty array if none are configured
 * @throws UnknownHostException if a given interface name is invalid
 */
private static SocketAddress[] getLocalInterfaceAddrs(
    String interfaceNames[]) throws UnknownHostException {
  List<SocketAddress> localAddrs = new ArrayList<SocketAddress>();
  for (String interfaceName : interfaceNames) {
    if (InetAddresses.isInetAddress(interfaceName)) {
      localAddrs.add(new InetSocketAddress(interfaceName, 0));
    } else if (NetUtils.isValidSubnet(interfaceName)) {
      for (InetAddress addr : NetUtils.getIPs(interfaceName, false)) {
        localAddrs.add(new InetSocketAddress(addr, 0));
      }
    } else {
      for (String ip : DNS.getIPs(interfaceName, false)) {
        localAddrs.add(new InetSocketAddress(ip, 0));
      }
    }
  }
  return localAddrs.toArray(new SocketAddress[localAddrs.size()]);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:34,代码来源:DFSClient.java

示例4: isValidIpString

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
 * Validates IP string, both IPV6 and IPV4
 * Also accounts for CIDR notation
 * Examples:
 * fe80::3ab1:dbff:fed1:c62d/64
 * 2001:db8::
 * 192.168.0.1
 * 2001:db8::/116
 * 192.168.0.0/32
 * ::/0
 *
 * @param address
 * @return
 */
public static boolean isValidIpString (String address) {
    int slashIndex = address.lastIndexOf('/');
    String ipAddressPart = address;
    Integer subnetPart;
    if (slashIndex != -1) {
        ipAddressPart = address.substring(0, slashIndex);
        try {
            subnetPart = Integer.parseInt(address.substring(slashIndex + 1, address.length()));
        } catch (NumberFormatException nfe) {
            return false;
        }
        if (subnetPart < 0) {
            return false;
        }
        if (subnetPart > 128) {
            return false;
        }
        if (subnetPart > 32 && ipAddressPart.contains(".")) {
            return false;
        }
    }
    return InetAddresses.isInetAddress(ipAddressPart);
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:38,代码来源:IpAddressValidator.java

示例5: readHost

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
private static String readHost(ConsoleReader reader, PrintWriter out, String prompt) {
  try {
    String inputString = readInputString(reader, out, prompt);

    if (InetAddresses.isInetAddress(inputString)) {
      return inputString;
    }
    out.println("Error, " + inputString + " is not a valid inet address");
  } catch (Exception exp) {
    if (WorfCLI.verbose) {
      exp.printStackTrace();
    }
    out.println("Error, unable to read the host. error=" + exp.getMessage());
  }
  return null;
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:17,代码来源:WorfInteractive.java

示例6: readInteger

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
private static String readInteger(ConsoleReader reader, PrintWriter out, String prompt) {
  try {
    String inputString = readInputString(reader, out, prompt);

    if (NumberUtils.isNumber(inputString)) {
      return inputString;
    }

    if (InetAddresses.isInetAddress(inputString)) {
      return inputString;
    }
    out.println("Error, " + inputString + " is not a number");
  } catch (Exception exp) {
    if (WorfCLI.verbose) {
      exp.printStackTrace();
    }
    out.println("Error, unable to read the host. error=" + exp.getMessage());
  }
  return null;
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:21,代码来源:WorfInteractive.java

示例7: buildAlternativeNames

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
private GeneralNames buildAlternativeNames(CertificateGenerationRequestParameters params) {
  String[] alternativeNamesList = params.getAlternativeNames();
  if (alternativeNamesList == null){
    return null;
  }
  GeneralNamesBuilder builder = new GeneralNamesBuilder();

  for (String name :alternativeNamesList) {
    if (InetAddresses.isInetAddress(name)) {
      builder.addName(new GeneralName(GeneralName.iPAddress, name));
    } else  {
      builder.addName(new GeneralName(GeneralName.dNSName, name));
    }
  }
  return builder.build();
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:17,代码来源:CertificateGenerationParameters.java

示例8: resolveClusterNode

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
private String resolveClusterNode(String clusterNodeName) {
  if (InetAddresses.isInetAddress(clusterNodeName)) {
    return DEFAULT_NETWORK_LOCATION;
  }
  String hostName = clusterNodeName.split("\\.")[0];
  PodCIDRLookup lookup = getOrFetchPodCIDR();
  if (lookup.containsNode(clusterNodeName) || lookup.containsNode(hostName)) {
    return getNetworkPathDir(hostName);
  }
  return DEFAULT_NETWORK_LOCATION;
}
 
开发者ID:apache-spark-on-k8s,项目名称:kubernetes-HDFS,代码行数:12,代码来源:PodCIDRToNodeMapping.java

示例9: resolvePodIP

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
private String resolvePodIP(String podIP) {
  if (!InetAddresses.isInetAddress(podIP)) {
    return DEFAULT_NETWORK_LOCATION;
  }
  PodCIDRLookup lookup = getOrFetchPodCIDR();
  String nodeName = lookup.findNodeByPodIP(podIP);
  if (nodeName.length() > 0) {
    return getNetworkPathDir(nodeName);
  }
  return DEFAULT_NETWORK_LOCATION;
}
 
开发者ID:apache-spark-on-k8s,项目名称:kubernetes-HDFS,代码行数:12,代码来源:PodCIDRToNodeMapping.java

示例10: simpleHostname

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
 * Given a full hostname, return the word upto the first dot.
 * @param fullHostname the full hostname
 * @return the hostname to the first dot
 */
public static String simpleHostname(String fullHostname) {
  if (InetAddresses.isInetAddress(fullHostname)) {
    return fullHostname;
  }
  int offset = fullHostname.indexOf('.');
  if (offset != -1) {
    return fullHostname.substring(0, offset);
  }
  return fullHostname;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:16,代码来源:StringUtils.java

示例11: withIpAccessRestrictedToThese

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
public Radiator withIpAccessRestrictedToThese(String... ips) {
    this.ips = ips;
    for (String ip : ips) {
        if (!InetAddresses.isInetAddress(ip)) {
            throw new NotAnIPAddress();
        }
    }
    return this;
}
 
开发者ID:BuildRadiator,项目名称:BuildRadiator,代码行数:10,代码来源:Radiator.java

示例12: parseDNFromHostsEntry

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
 * Parse a DatanodeID from a hosts file entry
 * @param hostLine of form [hostname|ip][:port]?
 * @return DatanodeID constructed from the given string
 */
private DatanodeID parseDNFromHostsEntry(String hostLine) {
  DatanodeID dnId;
  String hostStr;
  int port;
  int idx = hostLine.indexOf(':');

  if (-1 == idx) {
    hostStr = hostLine;
    port = DFSConfigKeys.DFS_DATANODE_DEFAULT_PORT;
  } else {
    hostStr = hostLine.substring(0, idx);
    port = Integer.parseInt(hostLine.substring(idx+1));
  }

  if (InetAddresses.isInetAddress(hostStr)) {
    // The IP:port is sufficient for listing in a report
    dnId = new DatanodeID(hostStr, "", "", port,
        DFSConfigKeys.DFS_DATANODE_HTTP_DEFAULT_PORT,
        DFSConfigKeys.DFS_DATANODE_HTTPS_DEFAULT_PORT,
        DFSConfigKeys.DFS_DATANODE_IPC_DEFAULT_PORT);
  } else {
    String ipAddr = "";
    try {
      ipAddr = InetAddress.getByName(hostStr).getHostAddress();
    } catch (UnknownHostException e) {
      LOG.warn("Invalid hostname " + hostStr + " in hosts file");
    }
    dnId = new DatanodeID(ipAddr, hostStr, "", port,
        DFSConfigKeys.DFS_DATANODE_HTTP_DEFAULT_PORT,
        DFSConfigKeys.DFS_DATANODE_HTTPS_DEFAULT_PORT,
        DFSConfigKeys.DFS_DATANODE_IPC_DEFAULT_PORT);
  }
  return dnId;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:DatanodeManager.java

示例13: getHostNameMinusDomain

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
 * @param hostname
 * @return hostname minus the domain, if there is one (will do pass-through on ip addresses)
 */
static String getHostNameMinusDomain(final String hostname) {
  if (InetAddresses.isInetAddress(hostname)) return hostname;
  String [] parts = hostname.split("\\.");
  if (parts == null || parts.length == 0) return hostname;
  return parts[0];
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:11,代码来源:ServerName.java

示例14: setDomainField

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
private void setDomainField(String url) {
	try {
		URL u = URL.parse(url);
		String hostString = u.host().toHumanString();
		String domain;
		if (!"localhost".equalsIgnoreCase(hostString) && !InetAddresses.isInetAddress(hostString)) {
			domain = InternetDomainName.from(hostString).topPrivateDomain().toString();
		} else {
			domain = hostString;
		}
		doc.add(new StringField(FIELD_DOMAIN, domain, Field.Store.YES));
	} catch (GalimatiasParseException e1) {
		LOG.error("Unable to parse url {}", url);
	}
}
 
开发者ID:abuchanan920,项目名称:historybook,代码行数:16,代码来源:IndexDocumentAdapter.java

示例15: match

import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
@Override
public void match(AccessLog accessLog) throws EventorException {
    String remoteAddr = (String)accessLog.readAtPath("request.x_forwarded_for");
    if (!InetAddresses.isInetAddress(remoteAddr)) {
        remoteAddr = (String)accessLog.readAtPath("request.remote_addr");
    }

    if (!InetAddresses.isInetAddress(remoteAddr)) {
        throw new DropEventException(String.format("Invalid remote address (IP) %s.", remoteAddr));
    }

    accessLog.builder.payload.put(Output.REMOTE_ADDR.name, remoteAddr);
}
 
开发者ID:webaio,项目名称:processor,代码行数:14,代码来源:RemoteAddrMatcherImpl.java


注:本文中的com.google.common.net.InetAddresses.isInetAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。