List of usage examples for java.net InetAddress isSiteLocalAddress
public boolean isSiteLocalAddress()
From source file:de.forsthaus.gui.service.impl.GuiLoginLoggingServiceImpl.java
@Override public void fillIp2CountryOnceForAppUpdate() { final List<SecLoginlog> originList = getAllLogs(); int count = 0; int localCount = 0; int checkCount = 0; int updateCount = 0; int unknownCount = 0; int unknownsysCCCount = 0; for (final SecLoginlog secLoginlog : originList) { count++;/*from w w w . jav a2 s .co m*/ // check if no entry exists for this login if (secLoginlog.getIp2Country() == null) { IpToCountry ipToCountry = null; try { // try to get a ipToCountry for the IP from the table final InetAddress inetAddress = InetAddress.getByName(secLoginlog.getLglIp()); // Skip a local ip. Therefore is no country to identify. if (inetAddress.isLoopbackAddress() || inetAddress.isSiteLocalAddress()) { localCount++; continue; } checkCount++; ipToCountry = getIpToCountryService().getIpToCountry(inetAddress); // if found than get the CountryCode object for it and save // all if (ipToCountry != null) { final String code2 = ipToCountry.getIpcCountryCode2(); final CountryCode sysCC = getCountryCodeService().getCountryCodeByCode2(code2); if (sysCC != null) { final Ip2Country ip2 = getIp2CountryService().getNewIp2Country(); ip2.setCountryCode(sysCC); // save all getIp2CountryService().saveOrUpdate(ip2); secLoginlog.setIp2Country(ip2); getLoginLoggingService().update(secLoginlog); updateCount++; } else { unknownsysCCCount++; } continue; } } catch (final UnknownHostException e) { try { Messagebox.show(e.getLocalizedMessage()); } catch (final InterruptedException e1) { throw new RuntimeException(e1); } } unknownCount++; } } if (logger.isInfoEnabled()) { logger.info("Ueberpruefte SecLoginlog " + count); logger.info("davon localhost: " + localCount); logger.info("hostcheck: " + checkCount); logger.info("SecLoginlog updates: " + updateCount); logger.info("Hosts, denen kein SysCountryCode zugeordnet werden konnte: : " + unknownsysCCCount); logger.info("unbekannte Hosts: " + unknownCount); } }
From source file:com.cloud.utils.net.NetUtils.java
public static boolean isSiteLocalAddress(final String ipAddress) { if (ipAddress == null) { return false; } else {/*from w w w.jav a 2 s . co m*/ final InetAddress ip = parseIpAddress(ipAddress); if (ip != null) { return ip.isSiteLocalAddress(); } return false; } }
From source file:de.forsthaus.gui.service.impl.GuiLoginLoggingServiceImpl.java
@Override public int updateIp2CountryFromLookUpHost(List<SecLoginlog> list) { int countRec = 0; final List<SecLoginlog> originList = list; for (final SecLoginlog secLoginlog : originList) { if (secLoginlog.getIp2Country() != null) { final Ip2Country ip2c = secLoginlog.getIp2Country(); try { // try to get a ipToCountry for the IP from the table final InetAddress inetAddress = InetAddress.getByName(secLoginlog.getLglIp()); // Skip a local ip. Therefore is no country to identify. if (inetAddress.isLoopbackAddress() || inetAddress.isSiteLocalAddress()) { continue; }//w ww.j a v a 2 s. co m if (StringUtils.isEmpty(ip2c.getI2cCity())) { final IpLocator ipl = getIp2CountryService().hostIpLookUpIp(secLoginlog.getLglIp()); // /** For testing on a local tomcat */ // IpLocator ipl = // getIp2CountryService().hostIpLookUpIp("95.111.227.104"); if (ipl != null) { if (logger.isDebugEnabled()) { logger.debug("hostLookUp resolved for : " + secLoginlog.getLglIp()); } ip2c.setI2cCity(ipl.getCity()); ip2c.setI2cLatitude(ipl.getLatitude()); ip2c.setI2cLongitude(ipl.getLongitude()); getIp2CountryService().saveOrUpdate(ip2c); secLoginlog.setIp2Country(ip2c); getLoginLoggingService().saveOrUpdate(secLoginlog); countRec = countRec + 1; } } } catch (final Exception e) { logger.warn("", e); continue; } } else { // create a new entry final Ip2Country ip2 = getIp2CountryService().getNewIp2Country(); try { // try to get a ipToCountry for the IP from the table final InetAddress inetAddress = InetAddress.getByName(secLoginlog.getLglIp()); // Skip a local ip. Therefore is no country to identify. if (inetAddress.isLoopbackAddress() || inetAddress.isSiteLocalAddress()) { continue; } final IpLocator ipl = getIp2CountryService().hostIpLookUpIp(secLoginlog.getLglIp()); // /** For testing on a local tomcat */ // IpLocator ipl = // getIp2CountryService().hostIpLookUpIp("95.111.227.104"); if (ipl != null) { if (logger.isDebugEnabled()) { logger.debug("hostLookUp resolved for : " + secLoginlog.getLglIp()); } final CountryCode sysCC = getCountryCodeService() .getCountryCodeByCode2(ipl.getCountryCode()); ip2.setCountryCode(sysCC); ip2.setI2cCity(ipl.getCity()); ip2.setI2cLatitude(ipl.getLatitude()); ip2.setI2cLongitude(ipl.getLongitude()); getIp2CountryService().saveOrUpdate(ip2); secLoginlog.setIp2Country(ip2); getLoginLoggingService().saveOrUpdate(secLoginlog); countRec = countRec + 1; } } catch (final Exception e) { logger.warn("", e); continue; } } } return countRec; }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobConfigurationService.java
/** * Interface method implementation.//from w w w. j a va2s . c o m * Also sets the hostName * @see JobConfigurationService#setPort(int) */ @Override public void setPort(int port) { String hostName = ""; String ipAddr = ""; try { hostName = InetAddress.getLocalHost().getHostName(); ipAddr = InetAddress.getLocalHost().getHostAddress(); Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); //Iterate through all network interfaces while (nets.hasMoreElements()) { NetworkInterface netint = (NetworkInterface) nets.nextElement(); Enumeration<InetAddress> ips = netint.getInetAddresses(); //Iterate through all IP adddress while (ips.hasMoreElements()) { InetAddress ip = ips.nextElement(); //Take the first address which isn't a loopback and is in the local address if (!ip.isLoopbackAddress() && ip.isSiteLocalAddress()) { LOGGER.info("Host IP Address: " + ip.getHostAddress()); ipAddr = ip.getHostAddress(); break; } } } } catch (UnknownHostException e) { LOGGER.error("Error while getting hostName ", e); } catch (SocketException e) { LOGGER.error("Error while getting hostName ", e); } this.hostName = new JobHost(hostName, ipAddr, port); }
From source file:com.cloud.utils.net.NetUtils.java
public static boolean isValidPrivateIp(final String ipAddress, final String guestIPAddress) { final InetAddress privIp = parseIpAddress(ipAddress); if (privIp == null) { return false; }// www . ja va 2 s . co m if (!privIp.isSiteLocalAddress()) { return false; } String firstGuestOctet = "10"; if (guestIPAddress != null && !guestIPAddress.isEmpty()) { final String[] guestIPList = guestIPAddress.split("\\."); firstGuestOctet = guestIPList[0]; } final String[] ipList = ipAddress.split("\\."); if (!ipList[0].equals(firstGuestOctet)) { return false; } return true; }
From source file:com.momathink.common.tools.ToolMonitor.java
/** * ?ip/*www. j a v a2 s. c om*/ * @return : "111.111.111.111" */ private String getRealIp() { String netip = null;// IP try { Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces(); InetAddress ip = null; boolean finded = false;// ?IP while (netInterfaces.hasMoreElements() && !finded) { NetworkInterface ni = netInterfaces.nextElement(); Enumeration<InetAddress> address = ni.getInetAddresses(); while (address.hasMoreElements()) { ip = address.nextElement(); if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// IP netip = ip.getHostAddress(); finded = true; break; } } } } catch (Exception e) { } return netip; }
From source file:org.opendaylight.netvirt.openstack.netvirt.impl.BridgeConfigurationManagerImpl.java
private String getLocalControllerHostIpAddress() { String ipaddress = null;//from www. ja v a2 s . c o m try { for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces .hasMoreElements();) { NetworkInterface iface = ifaces.nextElement(); for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) { InetAddress inetAddr = inetAddrs.nextElement(); if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) { ipaddress = inetAddr.getHostAddress(); break; } } } } catch (Exception e) { LOG.warn("Exception while fetching local host ip address ", e); } return ipaddress; }
From source file:com.taobao.diamond.client.impl.DefaultDiamondPublisher.java
private String getHostAddress() { String address = "127.0.0.1"; try {/*from w w w . ja v a 2 s .c o m*/ Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface ni = en.nextElement(); Enumeration<InetAddress> ads = ni.getInetAddresses(); while (ads.hasMoreElements()) { InetAddress ip = ads.nextElement(); if (!ip.isLoopbackAddress() && ip.isSiteLocalAddress()) { return ip.getHostAddress(); } } } } catch (Exception e) { log.error("", e); } return address; }
From source file:org.parosproxy.paros.core.proxy.ProxyThread.java
private boolean isRecursive(HttpRequestHeader header) { try {/*from www . j av a2 s .c om*/ if (header.getHostPort() == inSocket.getLocalPort()) { String targetDomain = header.getHostName(); if (API.API_DOMAIN.equals(targetDomain)) { return true; } InetAddress targetAddress = InetAddress.getByName(targetDomain); if (parentServer.getProxyParam().isProxyIpAnyLocalAddress()) { if (targetAddress.isLoopbackAddress() || targetAddress.isSiteLocalAddress() || targetAddress.isAnyLocalAddress()) { return true; } } else if (targetAddress.equals(inSocket.getLocalAddress())) { return true; } } } catch (Exception e) { // ZAP: Log exceptions log.warn(e.getMessage(), e); } return false; }
From source file:org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProvider.java
private String getCurrentNodeIp() throws SocketException { final Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); Inet4Address top = null;//from w w w.ja v a 2 s . co m while (nis.hasMoreElements()) { final NetworkInterface ni = nis.nextElement(); final Enumeration<InetAddress> ips = ni.getInetAddresses(); while (ips.hasMoreElements()) { final InetAddress ip = ips.nextElement(); if (ip instanceof Inet4Address && !ip.isLinkLocalAddress()) { if (top == null) { top = (Inet4Address) ip; } else if (!top.isSiteLocalAddress() && ip.isSiteLocalAddress()) { top = (Inet4Address) ip; } } } } if (top == null) { throw new IllegalStateException("[galley] IP not found."); } return top.getHostAddress(); }