List of usage examples for com.google.common.net InetAddresses isInetAddress
public static boolean isInetAddress(String ipString)
From source file:com.difference.historybook.index.lucene.IndexDocumentAdapter.java
private void setDomainField(String url) { try {// w w w .j a va 2 s.c o m 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); } }
From source file:org.opendaylight.groupbasedpolicy.renderer.opflex.L3EprContext.java
/** * Create an L3 Endpoint in the Endopint Registry * //from ww w. ja v a2s . c om * @param req The OpFlex EP Declaration Request message * @param id The identity of the EP to create */ public void createL3Ep(String context, List<String> ids, Identity id) { EndpointL3Builder epBuilder = new EndpointL3Builder(); for (String l3Addr : ids) { if (InetAddresses.isInetAddress(l3Addr)) { id.addId(l3Addr); } } id.setContext(context); epBuilder.setIpAddress(id.getL3Identity()); epBuilder.setL3Context(id.getL3Context()); epBuilder.setL3Address(id.getL3Addresses()); // TODO: where do we get the tenant and EPG? TenantId tid = new TenantId(DEFAULT_TENANT); EndpointGroupId eid = new EndpointGroupId(DEFAULT_EPG); epBuilder.setTenant(tid); epBuilder.setEndpointGroup(eid); EndpointL3 ep = epBuilder.build(); InstanceIdentifier<EndpointL3> iid = InstanceIdentifier.builder(Endpoints.class) .child(EndpointL3.class, ep.getKey()).build(); WriteTransaction wt = dataProvider.newWriteOnlyTransaction(); wt.put(LogicalDatastoreType.OPERATIONAL, iid, ep); wt.submit(); }
From source file:org.apache.hadoop.util.MachineList.java
/** * Accepts a collection of ip/cidr/host addresses * //from ww w . ja va2s . c om * @param hostEntries * @param addressFactory addressFactory to convert host to InetAddress */ public MachineList(Collection<String> hostEntries, InetAddressFactory addressFactory) { this.addressFactory = addressFactory; if (hostEntries != null) { if ((hostEntries.size() == 1) && (hostEntries.contains(WILDCARD_VALUE))) { all = true; ipAddresses = null; hostNames = null; cidrAddresses = null; } else { all = false; Set<String> ips = new HashSet<String>(); List<SubnetUtils.SubnetInfo> cidrs = new LinkedList<SubnetUtils.SubnetInfo>(); Set<String> hosts = new HashSet<String>(); for (String hostEntry : hostEntries) { //ip address range if (hostEntry.indexOf("/") > -1) { try { SubnetUtils subnet = new SubnetUtils(hostEntry); subnet.setInclusiveHostCount(true); cidrs.add(subnet.getInfo()); } catch (IllegalArgumentException e) { LOG.warn("Invalid CIDR syntax : " + hostEntry); throw e; } } else if (InetAddresses.isInetAddress(hostEntry)) { //ip address ips.add(hostEntry); } else { //hostname hosts.add(hostEntry); } } ipAddresses = (ips.size() > 0) ? ips : null; cidrAddresses = (cidrs.size() > 0) ? cidrs : null; hostNames = (hosts.size() > 0) ? hosts : null; } } else { all = false; ipAddresses = null; hostNames = null; cidrAddresses = null; } }
From source file:org.opennaas.extensions.router.model.utils.IPUtilsHelper.java
public static boolean validateIPv6Address(String ipAddress) { return InetAddresses.isInetAddress(ipAddress); }
From source file:org.smartdeveloperhub.curator.connector.protocol.ValidationUtil.java
static String validateHostname(final String hostname) { checkArgument(InetAddresses.isInetAddress(hostname) || isValidDomainName(hostname), TYPES.HOSTNAME_TYPE, hostname, "Host name '%s' is not valid"); return hostname; }
From source file:org.sonar.application.config.ClusterSettings.java
private static InetAddress convertToInetAddress(String text, String key) { InetAddress inetAddress;/*from www . j ava 2 s. c om*/ HostAndPort hostAndPort = HostAndPort.fromString(text); if (!InetAddresses.isInetAddress(hostAndPort.getHostText())) { try { inetAddress = InetAddress.getByName(hostAndPort.getHostText()); } catch (UnknownHostException e) { throw new MessageException(format("The interface address [%s] of [%s] cannot be resolved : %s", text, key, e.getMessage())); } } else { inetAddress = forString(hostAndPort.getHostText()); } return inetAddress; }
From source file:com.forerunnergames.tools.net.DefaultExternalAddressResolver.java
private boolean isValid(final Optional<String> ipAddress) { return ipAddress.isPresent() && InetAddresses.isInetAddress(ipAddress.get()); }
From source file:org.apache.hadoop.net.PodCIDRToNodeMapping.java
private String resolveClusterNode(String clusterNodeName) { if (InetAddresses.isInetAddress(clusterNodeName)) { return DEFAULT_NETWORK_LOCATION; }//w ww.jav a 2s. com String hostName = clusterNodeName.split("\\.")[0]; PodCIDRLookup lookup = getOrFetchPodCIDR(); if (lookup.containsNode(clusterNodeName) || lookup.containsNode(hostName)) { return getNetworkPathDir(hostName); } return DEFAULT_NETWORK_LOCATION; }
From source file:com.idlegandalf.ledd.fragments.AddDaemonDialog.java
@Override public void onShow(final DialogInterface dialog) { // start host discovery if (!mListening) { mNsdManager.discoverServices(SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, this); mListening = true;// w w w .ja va 2 s.c o m } final AlertDialog alertDialog = (AlertDialog) dialog; ip.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { ip_lay.setError(null); } }); alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mNsdManager.stopServiceDiscovery(AddDaemonDialog.this); AddStripeDialog.instance.onResume(); alertDialog.dismiss(); } }); alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String strIp = ip.getText().toString(); int port; if (strIp.contains(":")) { strIp = strIp.split(":")[0]; try { port = Integer.parseInt(ip.getText().toString().split(":")[1]); } catch (NumberFormatException e) { ip_lay.setError("Please check your port"); return; } if (port < 1024 || port > 65535) { ip_lay.setError("Port is out of range"); return; } } else { port = 1425; } if (InetAddresses.isInetAddress(strIp)) { LedDDaemon daemon = new LedDDaemon(strIp, port); if (!ledDDaemons.contains(daemon)) addDaemon(new LedDDaemon(strIp, port)); else ip_lay.setError("Daemon already exist"); } else { ip_lay.setError("No valid ip address"); } } }); }
From source file:org.apache.hadoop.net.PodCIDRToNodeMapping.java
private String resolvePodIP(String podIP) { if (!InetAddresses.isInetAddress(podIP)) { return DEFAULT_NETWORK_LOCATION; }//from w w w . j a v a 2s . com PodCIDRLookup lookup = getOrFetchPodCIDR(); String nodeName = lookup.findNodeByPodIP(podIP); if (nodeName.length() > 0) { return getNetworkPathDir(nodeName); } return DEFAULT_NETWORK_LOCATION; }