/** * Returns the country the IP address is in. * * @param ipAddress * the IP address in long format. * @return the country the IP address is from. */ public synchronized Country getCountry(long ipAddress) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountry(ipAddress) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
protected String lookup(String ip) throws IOException { if (geoloc == null) { geoloc = new LookupService("./" + DIST_CACHE_GEOIP_NAME, LookupService.GEOIP_MEMORY_CACHE); } String country = geoloc.getCountry(ip).getName(); if ("N/A".equals(country)) { return null; } return country; }
@Override public Object getValueAt(int rowIndex, int columnIndex) { if (countryLookup == null) { try { countryLookup = new LookupService(ConfigSettings.getGeoIPCountryFile(), LookupService.GEOIP_MEMORY_CACHE); } catch (IOException ex) { Logger.getLogger(IpModel.class.getName()).log(Level.SEVERE, null, ex); } } if (rowIndex < getRowCount()) { String rowStr = (String) data.get(rowIndex); if (rowStr == null) { return null; } switch (columnIndex) { case 0: return rowStr; case 1: return "<n/a>"; case 2: if (countryLookup != null) { return countryLookup.getCountry(rowStr).getName(); } else { return "<n/a>"; } } } return null; }
/** * Returns the country the IP address is in. * * @param addr * the IP address as Inet6Address. * @return the country the IP address is from. */ public synchronized Country getCountryV6(InetAddress addr) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountryV6(addr) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
/** Converts int value to country code. * * @param host ip address as int type by network byte order(big endian) */ public static String getCountryCode(int host) { return lookup.getCountry(host).getCode(); }
String country = lookupService.getCountry(logEntry.getHost()).getName(); countries.add(country); register(country, countriesForNewsFeeds);
/** * Returns the country the IP address is in. * * @param addr * the IP address as Inet6Address. * @return the country the IP address is from. */ public synchronized Country getCountryV6(InetAddress addr) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountryV6(addr) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
public static String getCountryCode(String host) { return lookup.getCountry(host).getCode(); } }
/** * Returns the country the IP address is in. * * @param ipAddress the IP address in long format. * @return the country the IP address is from. */ public Country getCountry(long ipAddress) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountry(ipAddress) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
public static String getCountryCode(String host) { return lookup.getCountry(host).getCode(); }
/** * Returns the country the IP address is in. * * @param ipAddress * the IP address in long format. * @return the country the IP address is from. */ public synchronized Country getCountry(long ipAddress) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountry(ipAddress) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
/** Converts binary(byte array) to country code. * In case of IPv4, it is 4 bytes length. * * @param host ip address as byte array type by network byte order(big endian) */ public static String getCountryCode(byte [] host) { InetAddress addr; try { addr = InetAddress.getByAddress(host); } catch (UnknownHostException e) { LOG.error("Unknown host: " + IPconvertUtil.bytes2ipstr(host)); return ""; } return lookup.getCountry(addr).getCode(); } }
/** * Returns the country the IP address is in. * * @param addr the IP address as Inet6Address. * @return the country the IP address is from. */ public Country getCountryV6(InetAddress addr) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountryV6(addr) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
protected String lookup(String ip, String filename) throws HiveException { try { if (geoloc == null) { URL u = getClass().getClassLoader().getResource(filename); if (u == null) { throw new HiveException("Couldn't find geolocation file '" + filename + "'"); } geoloc = new LookupService(u.getFile(), LookupService.GEOIP_MEMORY_CACHE); } String countryCode = geoloc.getCountry(ip).getCode(); if ("--".equals(countryCode)) { return null; } return countryCode; } catch (IOException e) { throw new HiveException("Caught IO exception", e); } }
/** * Returns the country the IP address is in. * * @param ipAddress the IP address in long format. * @return the country the IP address is from. */ public Country getCountry(long ipAddress) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountry(ipAddress) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
/** * Returns the country the IP address is in. * * @param ipAddress * the IP address in long format. * @return the country the IP address is from. */ public synchronized Country getCountry(long ipAddress) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountry(ipAddress) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
/** * Returns the country the IP address is in. * * @param addr * the IP address as Inet6Address. * @return the country the IP address is from. */ public synchronized Country getCountryV6(InetAddress addr) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountryV6(addr) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
/** * Returns the country the IP address is in. * * @param addr the IP address as Inet6Address. * @return the country the IP address is from. */ public Country getCountryV6(InetAddress addr) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountryV6(addr) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }
/** * Returns the country the IP address is in. * * @param addr the IP address as Inet6Address. * @return the country the IP address is from. */ public Country getCountryV6(InetAddress addr) { if (file == null && (dboptions & GEOIP_MEMORY_CACHE) == 0) { throw new IllegalStateException("Database has been closed."); } int ret = seekCountryV6(addr) - COUNTRY_BEGIN; if (ret == 0) { return UNKNOWN_COUNTRY; } else { return new Country(countryCode[ret], countryName[ret]); } }