I am looking for the sample code to get Exact Location of IP. I did goggling but haven't find any Sample code. Thank You..
-
let me test. nullPainterKhAn SaAb– KhAn SaAb2013-04-24 07:22:03 +00:00Commented Apr 24, 2013 at 7:22
-
Note that the free versions of the MaxMind databases are updated less regularly than the commercial versions. Also note that the notion of 'exact location' is relative when it comes to IP and may be based on the city where your ISP is based, depending on the size of your country, ISP etc.nullPainter– nullPainter2013-04-24 07:29:46 +00:00Commented Apr 24, 2013 at 7:29
-
check the ip2asn2cc library: github.com/AxLabs/ip2asn2ccgsmachado– gsmachado2020-05-13 23:23:11 +00:00Commented May 13, 2020 at 23:23
Add a comment
|
1 Answer
I've used the MaxMind GeoIP Lite database to good success before. Both city and country databases and APIs are available.
An example of usage is:
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);
}
2 Comments
syam houng
try this code in here mkyong.com/java/java-find-location-using-ip-address
nullPainter
Did this answer ever solve your problems, @KhAn SaAb? If so, it'd be great if it coudl be marked as accepted.