How to get running machine region from Java

207 views Asked by At

I am looking a way to get the region from the given IP address.I found that there are plenty of Apis available on the internet. Eg:GeoLite but the problem was that my IP adresses are resides in private network so those are not visible for publicly.My question is that is there any native way to achieve this on different platforms(Linux,Windows) using Java.

Get IP adress from Java

InetAddress addr = InetAddress.getLocalHost();
 System.out.println(addr.getHostAddress());

GeoLite code snippet

LookupService lookup =new LookupService("src\\main\\resources\\GeoLocationDB\\GeoLiteCity.dat",LookupService.GEOIP_CHECK_CACHE);
     Location locationServices = lookup.getLocation("10.xx.xx.xxx");

    System.out.println(locationServices.city);//throws a null 
0

There are 0 answers