List of usage examples for java.net InetAddress isAnyLocalAddress
public boolean isAnyLocalAddress()
From source file:org.alfresco.util.remote.server.socket.HostConfigurableSocketFactory.java
public void setHost(String host) { try {//from ww w .j a v a2s .c o m InetAddress hostAddress = InetAddress.getByName(host); if (!hostAddress.isAnyLocalAddress()) { this.host = hostAddress; } } catch (UnknownHostException e) { throw new RuntimeException(e.toString()); } }
From source file:org.cruxframework.crux.tools.server.JettyDevServer.java
protected void processParameters(Collection<ConsoleParameter> parameters) { for (ConsoleParameter parameter : parameters) { if (parameter.getName().equals("-appRootDir")) { appRootDir = new File(parameter.getValue()); } else if (parameter.getName().equals("-addDevelopmentComponents")) { this.addDevelopmentComponents = true; } else if (parameter.getName().equals("-pageOutputCharset")) { pageOutputCharset = parameter.getValue(); } else if (parameter.getName().equals("-bindAddress")) { try { InetAddress bindAddress = InetAddress.getByName(parameter.getValue()); if (bindAddress.isAnyLocalAddress()) { this.bindAddress = InetAddress.getLocalHost().getHostAddress(); } else { this.bindAddress = parameter.getValue(); }//from w w w .ja va 2 s. c o m } catch (Exception e) { //Use default } } else if (parameter.getName().equals("-port")) { port = Integer.parseInt(parameter.getValue()); } } }
From source file:io.cloudslang.content.utilities.services.osdetector.LocalOsDetectorService.java
private boolean isLocalAddress(String host) { InetAddress address; try {//w ww . j a v a 2 s . c o m address = getByName(host); } catch (UnknownHostException ignored) { return false; } if (address.isAnyLocalAddress() || address.isLoopbackAddress()) { return true; } try { return getByInetAddress(address) != null; } catch (SocketException ignored) { return false; } }
From source file:org.bgp4j.config.nodes.impl.ClientConfigurationImpl.java
public ClientConfigurationImpl(InetAddress addr, int port) throws ConfigurationException { if (addr == null) throw new ConfigurationException("null remote address not allowed"); if (addr.isAnyLocalAddress()) throw new ConfigurationException("wildcard remote address not allowed"); if (port < 0 || port > 65535) throw new ConfigurationException("port " + port + " not allowed"); this.remoteAddress = new InetSocketAddress(addr, port); }
From source file:com.opensoc.enrichment.adapters.geo.GeoMysqlAdapter.java
@SuppressWarnings("unchecked") @Override//w w w.jav a2s .c o m public JSONObject enrich(String metadata) { ResultSet resultSet = null; try { _LOG.trace("[OpenSOC] Received metadata: " + metadata); InetAddress addr = InetAddress.getByName(metadata); if (addr.isAnyLocalAddress() || addr.isLoopbackAddress() || addr.isSiteLocalAddress() || addr.isMulticastAddress() || !ipvalidator.isValidInet4Address(metadata)) { _LOG.trace("[OpenSOC] Not a remote IP: " + metadata); _LOG.trace("[OpenSOC] Returning enrichment: " + "{}"); return new JSONObject(); } _LOG.trace("[OpenSOC] Is a valid remote IP: " + metadata); statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String locid_query = "select IPTOLOCID(\"" + metadata + "\") as ANS"; resultSet = statement.executeQuery(locid_query); if (resultSet == null) throw new Exception( "Invalid result set for metadata: " + metadata + ". Query run was: " + locid_query); resultSet.last(); int size = resultSet.getRow(); if (size == 0) throw new Exception("No result returned for: " + metadata + ". Query run was: " + locid_query); resultSet.beforeFirst(); resultSet.next(); String locid = null; locid = resultSet.getString("ANS"); if (locid == null) throw new Exception("Invalid location id for: " + metadata + ". Query run was: " + locid_query); String geo_query = "select * from location where locID = " + locid + ";"; resultSet = statement.executeQuery(geo_query); if (resultSet == null) throw new Exception("Invalid result set for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.last(); size = resultSet.getRow(); if (size == 0) throw new Exception("No result id returned for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.beforeFirst(); resultSet.next(); JSONObject jo = new JSONObject(); jo.put("locID", resultSet.getString("locID")); jo.put("country", resultSet.getString("country")); jo.put("city", resultSet.getString("city")); jo.put("postalCode", resultSet.getString("postalCode")); jo.put("latitude", resultSet.getString("latitude")); jo.put("longitude", resultSet.getString("longitude")); jo.put("dmaCode", resultSet.getString("dmaCode")); jo.put("locID", resultSet.getString("locID")); jo.put("location_point", jo.get("longitude") + "," + jo.get("latitude")); _LOG.debug("Returning enrichment: " + jo); return jo; } catch (Exception e) { e.printStackTrace(); _LOG.error("Enrichment failure: " + e); return new JSONObject(); } }
From source file:org.apache.metron.enrichment.adapters.geo.GeoMysqlAdapter.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a va 2s . c om*/ public JSONObject enrich(String metadata) { ResultSet resultSet = null; try { _LOG.trace("[Metron] Received metadata: " + metadata); InetAddress addr = InetAddress.getByName(metadata); if (addr.isAnyLocalAddress() || addr.isLoopbackAddress() || addr.isSiteLocalAddress() || addr.isMulticastAddress() || !ipvalidator.isValidInet4Address(metadata)) { _LOG.trace("[Metron] Not a remote IP: " + metadata); _LOG.trace("[Metron] Returning enrichment: " + "{}"); return new JSONObject(); } _LOG.trace("[Metron] Is a valid remote IP: " + metadata); statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String locid_query = "select IPTOLOCID(\"" + metadata + "\") as ANS"; resultSet = statement.executeQuery(locid_query); if (resultSet == null) throw new Exception( "Invalid result set for metadata: " + metadata + ". Query run was: " + locid_query); resultSet.last(); int size = resultSet.getRow(); if (size == 0) throw new Exception("No result returned for: " + metadata + ". Query run was: " + locid_query); resultSet.beforeFirst(); resultSet.next(); String locid = null; locid = resultSet.getString("ANS"); if (locid == null) throw new Exception("Invalid location id for: " + metadata + ". Query run was: " + locid_query); String geo_query = "select * from location where locID = " + locid + ";"; resultSet = statement.executeQuery(geo_query); if (resultSet == null) throw new Exception("Invalid result set for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.last(); size = resultSet.getRow(); if (size == 0) throw new Exception("No result id returned for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.beforeFirst(); resultSet.next(); JSONObject jo = new JSONObject(); jo.put("locID", resultSet.getString("locID")); jo.put("country", resultSet.getString("country")); jo.put("city", resultSet.getString("city")); jo.put("postalCode", resultSet.getString("postalCode")); jo.put("latitude", resultSet.getString("latitude")); jo.put("longitude", resultSet.getString("longitude")); jo.put("dmaCode", resultSet.getString("dmaCode")); jo.put("locID", resultSet.getString("locID")); jo.put("location_point", jo.get("longitude") + "," + jo.get("latitude")); _LOG.debug("Returning enrichment: " + jo); return jo; } catch (Exception e) { e.printStackTrace(); _LOG.error("Enrichment failure: " + e); return new JSONObject(); } }
From source file:org.apache.hadoop.hdfs.DFSUtil.java
/** * Substitute a default host in the case that an address has been configured * with a wildcard. This is used, for example, when determining the HTTP * address of the NN -- if it's configured to bind to 0.0.0.0, we want to * substitute the hostname from the filesystem URI rather than trying to * connect to 0.0.0.0.//from w ww . j a v a 2 s . com * * @param configuredAddress * the address found in the configuration * @param defaultHost * the host to substitute with, if configuredAddress * is a local/wildcard address. * @return the substituted address * @throws IOException * if it is a wildcard address and security is enabled */ @VisibleForTesting public static String substituteForWildcardAddress(String configuredAddress, String defaultHost) throws IOException { InetSocketAddress sockAddr = NetUtils.createSocketAddr(configuredAddress); InetSocketAddress defaultSockAddr = NetUtils.createSocketAddr(defaultHost + ":0"); final InetAddress addr = sockAddr.getAddress(); if (addr != null && addr.isAnyLocalAddress()) { if (UserGroupInformation.isSecurityEnabled() && defaultSockAddr.getAddress().isAnyLocalAddress()) { throw new IOException("Cannot use a wildcard address with security. " + "Must explicitly set bind address for Kerberos"); } return defaultHost + ":" + sockAddr.getPort(); } else { return configuredAddress; } }
From source file:io.netlibs.bgp.config.nodes.impl.ClientConfigurationImpl.java
public ClientConfigurationImpl(final InetAddress addr, final int port) throws ConfigurationException { if (addr == null) { throw new ConfigurationException("null remote address not allowed"); }/*w w w .j a v a2 s. c o m*/ if (addr.isAnyLocalAddress()) { throw new ConfigurationException("wildcard remote address not allowed"); } if ((port < 0) || (port > 65535)) { throw new ConfigurationException("port " + port + " not allowed"); } this.remoteAddress = new InetSocketAddress(addr, port); }
From source file:com.groupon.odo.bmp.ProxyServer.java
public void setLocalHost(InetAddress localHost) throws SocketException { if (localHost.isAnyLocalAddress() || localHost.isLoopbackAddress() || NetworkInterface.getByInetAddress(localHost) != null) { this.localHost = localHost; } else {/* www .j a v a 2s . c o m*/ throw new IllegalArgumentException("Must be address of a local adapter"); } }
From source file:org.apache.geode.internal.net.SocketCreator.java
/** * returns a set of the non-loopback InetAddresses for this machine */// w ww . j a v a2 s . co m public static Set<InetAddress> getMyAddresses() { Set<InetAddress> result = new HashSet<InetAddress>(); Set<InetAddress> locals = new HashSet<InetAddress>(); Enumeration<NetworkInterface> interfaces; try { interfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { throw new IllegalArgumentException( LocalizedStrings.StartupMessage_UNABLE_TO_EXAMINE_NETWORK_INTERFACES.toLocalizedString(), e); } while (interfaces.hasMoreElements()) { NetworkInterface face = interfaces.nextElement(); boolean faceIsUp = false; try { faceIsUp = face.isUp(); } catch (SocketException e) { InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance(); if (ids != null) { logger.info("Failed to check if network interface is up. Skipping {}", face, e); } } if (faceIsUp) { Enumeration<InetAddress> addrs = face.getInetAddresses(); while (addrs.hasMoreElements()) { InetAddress addr = addrs.nextElement(); if (addr.isLoopbackAddress() || addr.isAnyLocalAddress() || (!useLinkLocalAddresses && addr.isLinkLocalAddress())) { locals.add(addr); } else { result.add(addr); } } // while } } // while // fix for bug #42427 - allow product to run on a standalone box by using // local addresses if there are no non-local addresses available if (result.size() == 0) { return locals; } else { return result; } }