當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。