public Location getLocation(String str) { InetAddress addr; try { addr = InetAddress.getByName(str); } catch (UnknownHostException e) { return null; } return getLocation(addr); }
public Location getLocation(String str) { if (dnsService == 0) { InetAddress addr; try { addr = InetAddress.getByName(str); } catch (UnknownHostException e) { return null; } return getLocation(addr); } else { String str2 = getDnsAttributes(str); return getLocationwithdnsservice(str2); // TODO if DNS is not available, go to local file as backup } }
LookupService cl = new LookupService("/var/geolite/GeoLiteCity.dat", LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE); Location location = cl.getLocation("some ip address");
public Location getLocation(String str) { if (dnsService == 0) { InetAddress addr; try { addr = InetAddress.getByName(str); } catch (UnknownHostException e) { return null; } return getLocation(addr); } else { String str2 = getDnsAttributes(str); return getLocationwithdnsservice(str2); // TODO if DNS is not available, go to local file as backup } }
public Location getLocation(InetAddress addr) { return getLocation(bytesToLong(addr.getAddress())); }
public Location getLocation(String str) { if (dnsService == 0) { InetAddress addr; try { addr = InetAddress.getByName(str); } catch (UnknownHostException e) { return null; } return getLocation(addr); } else { String str2 = getDnsAttributes(str); return getLocationwithdnsservice(str2); // TODO if DNS is not available, go to local file as backup } }
public Location getLocation(String str) { InetAddress addr; try { addr = InetAddress.getByName(str); } catch (UnknownHostException e) { return null; } return getLocation(addr); }
public Location getLocation(String str) { InetAddress addr; try { addr = InetAddress.getByName(str); } catch (UnknownHostException e) { return null; } return getLocation(addr); }
LookupService cl = new LookupService("/var/geolite/GeoLiteCity.dat", LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE); Location location = cl.getLocation("some ip address");
LookupService lookup = new LookupService(file,LookupService.GEOIP_MEMORY_CACHE); Location locationServices = lookup.getLocation(ipAddress);
//ip address something like that 192.168.0.1 public String getCountryFromIP(String ipAddress) { File file = new File("resources/GeoLiteCity.dat"); LookupService lookup = new LookupService(file,LookupService.GEOIP_MEMORY_CACHE); Location locationServices = lookup.getLocation(ipAddress); return locationServices.countryName; }
File dbfile = new File("db/GeoLiteCity.dat"); LookupService lookupService = new LookupService(dbfile, LookupService.GEOIP_MEMORY_CACHE); Location location = lookupService.getLocation(ipAddress); // Populate region. Note that regionName is a MaxMind class, not an instance variable if (location != null) { location.region = regionName.regionNameByCode(location.countryCode, location.region); }
@Override public Map<String, Object> extractInformation(Object value) { Map<String, Object> m = new HashMap<String, Object>(); try { Location location = reader.getLocation(value.toString()); if (location != null) { m.put("ipCountry", location.countryCode); m.put("ipRegion", location.region); m.put("ipCity", location.city); } } catch (Exception ex) { LOG.error("Caught exception when looking up Geo IP for {}:", value, ex); } return m; }
public Location getLocation(InetAddress addr) { return getLocation(bytesToLong(addr.getAddress())); }
public Location getLocation(InetAddress addr) { return getLocation(bytesToLong(addr.getAddress())); }
public Location getLocation(InetAddress addr) { return getLocation(bytesToLong(addr.getAddress())); }
public Location getLocation(InetAddress addr) { return getLocation(bytesToLong(addr.getAddress())); }
public Location getLocation(InetAddress addr) { return getLocation(bytesToLong(addr.getAddress())); }
@Test public void testLookup() throws Exception { if (geoipLookup == null) { return; } Location loc = geoipLookup.getLocation("64.147.114.82"); assertEquals("United States", loc.countryName); assertEquals("New York", loc.city); loc = geoipLookup.getLocation("192.168.1.103"); assertNull(loc); } }
@Test public void testLookup() throws Exception { if (geoipLookup == null) { return; } Location loc = geoipLookup.getLocation("64.147.114.82"); assertEquals("United States", loc.countryName); assertEquals("New York", loc.city); loc = geoipLookup.getLocation("192.168.1.103"); assertNull(loc); } }