可以自己搭建,也可以直接使用现成的请求链接,每个月月初更新 ip 库
获取城市信息:http://ip.guoxinqi.cn/city/47.96.229.169
获取IP经纬度信息:http://ip.guoxinqi.cn/position/47.96.229.169
自己搭建:
可用于拦截操作、获取 IP 详细信息、及黑名单操作获取。
拦截操作: MvcConfigurer中addInterceptors中指定拦截方法(/** 全部请求拦截),在 FilterHandler 的 preHandle 方法可做拦截后的操作(例:黑名单拦截、请求拦截)
IP 详细信息获取: 使用 InterceptServer 方法获取 ip 的详细信息,可获取国家、省份、城市、经纬度 等。(结合拦截操作可实现黑名单拦截、白名单放行、拦截指定国家、省份、城市的拦截操作)
项目地址及介绍:https://gitee.com/qq1319426493/IP-Intercept
软件架构
使用 SpringBoot ,GeoLite2City
新建项目(IP-Intercept):
1、pom.xml 导包
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zwsd</groupId>
<artifactId>IP-Intercept</artifactId>
<version>1.0</version>
<name>IP-Intercept</name>
<url>http://www.example.com</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</depende