if (inetAddress.isLoopbackAddress() || inetAddress.isSiteLocalAddress()) {
continue;
}
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);