IP地址解析省份区域信息

2024-06-24 00:36

本文主要是介绍IP地址解析省份区域信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

背景

最近工作需要根据IP地址,解析通话所在省份。因此,在网上找了相关方案,作为存档记录下来。

在线接口

不做阐述。因为,一是网上可以很轻松的找到,没有必要多说。二是开发在内网中,多数不会让连接外网。三是多数花钱的方案,公司审批麻烦。

离线方案

调研了开源的ip2region,但是其不支持IPV6,因此使用mica-ip2region版。mica-ip2region,已内置了IP数据源,因此不需要自己单独添加IP数据源。如果,公司有自己的IP库,需要添加到数据源,需要研究ip2region如何生成IP数据源。

  • 依赖
    <properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><mica.ip2region.version>2.7.18.5</mica.ip2region.version><spring.version>2.7.13</spring.version></properties><dependencies><dependency><groupId>net.dreamlu</groupId><artifactId>mica-ip2region</artifactId><version>${mica.ip2region.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId><version>${spring.version}</version></dependency></dependencies>
  • 测试案例
package com.dayue;import net.dreamlu.mica.ip2region.config.Ip2regionConfiguration;
import net.dreamlu.mica.ip2region.config.Ip2regionProperties;
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
import net.dreamlu.mica.ip2region.impl.Ip2regionSearcherImpl;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class Demo {private static Ip2regionSearcher searcher;public static void main(String[] args) throws Exception {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();Ip2regionConfiguration configuration = new Ip2regionConfiguration();searcher = configuration.ip2regionSearcher(context, new Ip2regionProperties());((Ip2regionSearcherImpl) searcher).afterPropertiesSet();System.out.println(searcher.memorySearch("220.248.12.158"));System.out.println(searcher.memorySearch("222.240.36.135"));System.out.println(searcher.memorySearch("172.30.13.97"));System.out.println(searcher.memorySearch("223.26.64.0"));System.out.println(searcher.memorySearch("223.26.128.0"));System.out.println(searcher.memorySearch("223.26.67.0"));System.out.println(searcher.memorySearch("223.29.220.0"));System.out.println(searcher.memorySearch("82.120.124.0"));System.out.println(searcher.memorySearch("::ffff:1111:2222"));System.out.println(searcher.memorySearch("2001:db8::ffff:1111:2222"));System.out.println(searcher.memorySearch("::1"));System.out.println(searcher.memorySearch("2406:840:20::1"));System.out.println(searcher.memorySearch("2c0f:feb0:a::"));System.out.println(searcher.memorySearch("240e:109:8047::"));System.out.println(searcher.memorySearch("1111:1111:1111::1111"));}}

这篇关于IP地址解析省份区域信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1088714

相关文章

解析 XML 和 INI

XML 1.TinyXML库 TinyXML是一个C++的XML解析库  使用介绍: https://www.cnblogs.com/mythou/archive/2011/11/27/2265169.html    使用的时候,只要把 tinyxml.h、tinystr.h、tinystr.cpp、tinyxml.cpp、tinyxmlerror.cpp、tinyxmlparser.

通过高德api查询所有店铺地址信息

通过高德api查询所有店铺地址电话信息 需求:通过高德api查询所有店铺地址信息需求分析具体实现1、申请高德appkey2、下载types city 字典值3、具体代码调用 需求:通过高德api查询所有店铺地址信息 需求分析 查询现有高德api发现现有接口关键字搜索API服务地址: https://developer.amap.com/api/webservice/gui

echarts省份标注加散点效果

这个是安徽的效果图,鼠标移到红色标注或者对应的市区位置都会显示对应的数值。 先直接上代码: import anhuiMapJson from './anhui.json'getCoords: function(city) {var res = [];if (city != null) {for (var c in this.cityMap.features) {if (this.cityMa

时间服务器中,适用于国内的 NTP 服务器地址,可用于时间同步或 Android 加速 GPS 定位

NTP 是什么?   NTP 是网络时间协议(Network Time Protocol),它用来同步网络设备【如计算机、手机】的时间的协议。 NTP 实现什么目的?   目的很简单,就是为了提供准确时间。因为我们的手表、设备等,经常会时间跑着跑着就有误差,或快或慢的少几秒,时间长了甚至误差过分钟。 NTP 服务器列表 最常见、熟知的就是 www.pool.ntp.org/zo

tf.split()函数解析

API原型(TensorFlow 1.8.0): tf.split(     value,     num_or_size_splits,     axis=0,     num=None,     name='split' ) 这个函数是用来切割张量的。输入切割的张量和参数,返回切割的结果。  value传入的就是需要切割的张量。  这个函数有两种切割的方式: 以三个维度的张量为例,比如说一

【第十三课】区域经济可视化表达——符号表达与标注

一、前言 地图最直接的表达就是使用符号表达。使用符号可以把简单的点线面要 素渲染成最直观的地理符号,提高地图的可读性。只要掌握了 ArcGIS 符号制 作的技巧,分析符号并总结出规则,就可以制作符合要求的地图+符号。 (一)符号的选择与修改 符号的选择在制图中至关重要,使用符号选择器对话框可从多个可用样式 中选择符号,并且每个符号都有一个标签用来描述其图形特征,如颜色或类型, 利用这些标签可

[vivado][IP核]FFT

刘东华的IP核详解: 1、 2、

[vivado][IP核]DDS

刘东华的IP核详解: 1、 这里的是指IP核配置中的相位数据的宽度。 2、 实际使用此IP核时并没有“频率分辨率”可以配,是靠改变来变的。 3、 4、 5、 数据输出的ready在数据正式输出时才会有。 自己仿真: 使用SIN/COS LUT only的模式,使用一个累加器作为相位输入,不知怎么,输出为X。

[ip核][vivado]aurora

Xapp1193:  discovered:1)并不是所有芯片都支持aurora.xc7z010就没有。                     2)XDC文件的指令-允许未约束的引脚的存在:                 set_property BITSTREAM.General.UnconstrainedPins {Allow} [current_design] PG046

[ip核][vivado]Block Menory Gennerator 学习

<刘东华的xilinx系列FPGA芯片IP核详解>读书摘录: 1. 2. 3.