当前位置:网站首页>Obtain geographic location and coordinates according to ip address (offline method)
Obtain geographic location and coordinates according to ip address (offline method)
2022-07-30 06:39:00 【Weizhi】
Acquire geographic location information based on ip, without using http and webservice interfaces, reducing request time.We can take advantage of the GeoLite2 library, the GeoLite2 database is a free IP geolocation database, and the GeoLite2 Country and City database is updated on the first Tuesday of every month.The GeoLite2 ASN database is updated every Tuesday.
Database download: https://dev.maxmind.com/zh-hans/geoip/geoip2/geolite2/#i
java documentation: http://maxmind.github.io/GeoIP2-java/
The following is a tool class demo
1. First place the downloaded file in the resources directory, which uses the city database
2. Tool class writing
/*** ip geographic coordinate acquisition tool class*/public class Geoip2Client {public static Map getGenIp(String ipAddr){Map result = new HashMap<>();try{String dbPath = this.getClass().getClassLoader().getResource("GeoLite2-City.mmdb").getPath();// This is the location of the GeoIP2 or GeoLite2 database file, which is obtained from the project resources path, of course, it can also be written as an absolute pathFile database = new File(dbPath);DatabaseReader reader = new DatabaseReader.Builder(database).withCache(new CHMCache()).build();InetAddress ipAddress = InetAddress.getByName(ipAddr);CityResponse response = reader.city(ipAddress);Country country = response.getCountry();Subdivision subdivision = response.getMostSpecificSubdivision();City city = response.getCity();Location location = response.getLocation();result.put("lat",location.getLatitude());//Latituderesult.put("long",location.getLongitude()); // longituderesult.put("country",country.getNames().get("zh-CN"));// country nameresult.put("subdivision",subdivision.getNames().get("ja"));//provinceresult.put("city",city.getNames().get("ja")); // city} catch(Exception e){e.printStackTrace();}return result;}} 边栏推荐
- 批量自动归集
- uni-app使用npm命令安装组件
- Blind injection, error injection, wide byte injection, stack injection study notes
- vulnhub-XXE ctf安全真题
- sqli-labs less3/4打靶笔记
- Solution to TypeError The view function did not return a valid response. The function either returned None
- 记一次流量分析实战——安恒科技(八月ctf)
- [PASECA2019]honey_shop
- 2022CISCNmisc
- npm run serve starts error npm ERR Missing script "serve"
猜你喜欢

DVWA installation tutorial (understand what you don't understand · in detail)

sqli-labs less3/4打靶笔记

互联网商城盲盒app为何如此火爆
![[MATLAB]图像处理——交通标志的识别](/img/45/1a5797a17ebf6db965a64c85e0f037.png)
[MATLAB]图像处理——交通标志的识别

【OS】操作系统高频面试题英文版(1)

FastAPI Quick Start

Communication middleware Fast DDS basic concepts and communication examples
CTF之misc-流量分析

Offensive and defensive world easy_web

连接云服务器Docker中的Mysql 详细图文操作(全)
随机推荐
JDBC一文搞懂
通信中间件 Fast DDS 基础概念简述与通信示例
MySQL数据库之JDBC编程
【调优】一个 Spark 任务某天突然变慢怎么解决
div设置一个最小高度和最大高度,但是中间可以靠内容撑开
Jackson 序列化失败问题-oracle数据返回类型找不到对应的Serializer
php-fpm
MySQL-Explain详解
连接云服务器Docker中的Mysql 详细图文操作(全)
MongoDB快速入门与基本使用
jsonpath
js 去除掉对象中的null,‘‘,[],{}
npm基本使用
Volatility memory forensics - command shows
【无标题】ES5新特性
npm run serve starts error npm ERR Missing script "serve"
JDBC programming of MySQL database
【面经】米哈游数据开发面经
async/await用法详解
Remember a traffic analysis practice - Anheng Technology (August ctf)