新报: 根据IP获取物理地址不需要调用接口啦
一、 复制data文件夹到自己的项目当中
可以进行加载到这个文件即可 博主放入在项目的根目录当中
请移步Gitee pull 该文件 https://gitee.com/yangbuyi/ip_file
https://gitee.com/yangbuyi/ip_file
获取点击量来一波 https://www.yangbuyi.top/login.html
https://www.yangbuyi.top/login.html
带入maven依赖 因为这个编辑器的原因 复制依赖 显示不出来淦!!!! 图片自己打吧
org.lionsoul
ip2region
1.7.2
二、最重要的一步 编译地理位置
找到自己的项目地址
执行打开cmd 执行这段代码
java -Dfile.encoding=utf-8 -jar dbMaker-1.2.2.jar -src ./data/ip.merge.txt -region ./data/global_region.csv
java -Dfile.encoding=utf-8 -jar dbMaker-1.2.2.jar -src ./data/ip.merge.txt -region ./data/global_region.csv
请跟着一步步来
代码开始 创建iputils
package top.yangbuyi.system.webapi; import org.lionsoul.ip2region.DataBlock;
import org.lionsoul.ip2region.DbConfig;
import org.lionsoul.ip2region.DbSearcher;
import org.lionsoul.ip2region.Util; import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URLDecoder; /**
* description: 杨不易网站 :www.yangbuyi.top
* program: yangbuyi-erp-2020
* ClassName: iputils
* create: 2020-07-10 09:20
*
* @author: yangbuyi
* @since: JDK1.8
* @iputils:
**/ /**
* 具体请看 SQL当中的 data文件 和jar包
* 通过下面语句进行 编译 地理位置
* java -jar dbMaker-1.2.2.jar -src ./data/ip.merge.txt -region ./data/global_region.csv
*/ public class iputils { public static String getCityInfo(String ip) throws UnsupportedEncodingException {
//db
String dbPath = new File("SQL/data/ip2region.db").getPath();
dbPath = URLDecoder.decode(dbPath, "UTF-8");
File file = new File(dbPath);
if (file.exists() == false) {
System.out.println("Error: Invalid ip2region.db file");
}
//查询算法
int algorithm = DbSearcher.BTREE_ALGORITHM; //B-tree
//DbSearcher.BINARY_ALGORITHM //Binary
//DbSearcher.MEMORY_ALGORITYM //Memory
try {
DbConfig config = new DbConfig();
DbSearcher searcher = new DbSearcher(config, dbPath);
//define the method
Method method = null;
switch (algorithm) {
case DbSearcher.BTREE_ALGORITHM:
method = searcher.getClass().getMethod("btreeSearch", String.class);
break;
case DbSearcher.BINARY_ALGORITHM:
method = searcher.getClass().getMethod("binarySearch", String.class);
break;
case DbSearcher.MEMORY_ALGORITYM:
method = searcher.getClass().getMethod("memorySearch", String.class);
break;
}
DataBlock dataBlock = null;
if (Util.isIpAddress(ip) == false) {
System.out.println("Error: Invalid ip address");
}
dataBlock = (DataBlock) method.invoke(searcher, ip);
String decode = URLDecoder.decode(dataBlock.getRegion(), "UTF-8");
return decode;
} catch (Exception e) {
e.printStackTrace();
}
return null;
} public static void main(String[] args) throws Exception {
System.err.println(iputils.getCityInfo("106.18.167.102"));
} }
最后 测试代码
太累了吧!!!!
新报: 根据IP获取物理地址不需要调用接口啦的更多相关文章
- PHP根据ip获取地理位置(通过高德地图接口)
PHP根据ip获取地理位置(通过高德地图接口)<pre>//restapi.amap.com/v3/ip?key=2004f145cf3a39a72e9ca70ca4b2a1dc& ...
- ThinkPHP使用纯真IP获取物理地址时中文乱码问题
今天在用ThinkPHP通过纯真IP获取地址时,发现输出结果中文乱码,如图: 经查发现ThinkPHP的IpLocation.class.php类文件中说明:“由于使用UTF8编码 如果使用纯真IP地 ...
- php根据IP获取所在省份-百度api接口
这里用的file_put_contents,你也可以用别的,直接怼代码: //拼接传递的参数 $getData = array( 'query' => '127.0.0.1', 'resourc ...
- ASP.NET根据IP获取省市地址
1.在网站的跟路径下面添加 QQWry.dat 文件,这个文件是IP数据库文件 2.添加以下一个类 IPScanner C# 代码 复制 public class IPScanner { ...
- 几种获取IP 根据IP获取地址的方法 JS,第三方 新浪 网易 腾讯
第一种是利用纯真ip数据库,这个可以在网上找到很多,缺点是更新有点慢. 第二种是利用门户网站的接口 目前已知的有腾讯.新浪.网易.搜狐和Google提供IP地址查询API,但是找得到的只有腾讯.新浪和 ...
- 腾讯新浪通过IP地址获取当前地理位置(省份)的接口
腾讯新浪通过IP地址获取当前地理位置(省份)的接口 腾讯的接口是 ,返回数组 http://fw.qq.com/ipaddress 返回值 var IPData = new Array(" ...
- PHP通过IP 获取 地理位置(实例)
发布:JB02 来源:脚本学堂 分享一例php代码,实现通过IP地址获取访问者的地理位置,在php编程中经常用到,有需要的朋友参考下吧.本节内容:PHP通过IP获取地理位置 例子: 复制代码代码 ...
- PHP通过IP 获取 地理位置(实例代码)
发布:JB02 来源:脚本学堂 分享一例php代码,实现通过IP地址获取访问者的地理位置,在php编程中经常用到,有需要的朋友参考下吧.本节内容:PHP通过IP获取地理位置 例子: 复制代码代码示 ...
- 根据ip获取用户地理位置
各大网站都提供根据ip获取用户地理位置信息,这里以新浪的接口为例子 接口地址为:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js ...
- 根据IP获取所在的国家城市
根据IP获取所在的国家城市 新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:htt ...
随机推荐
- 为什么 Python 代码在函数中运行得更快?
哈喽大家好,我是咸鱼 当谈到编程效率和性能优化时,Python 常常被调侃为"慢如蜗牛" 有趣的是,Python 代码在函数中运行往往比在全局范围内运行要快得多 小伙伴们可能会有这 ...
- Linux服务器使用Redis作为数据缓存,并用log4j2进行日志记录
前言 个人网站使用Vue作为前端,SpringBoot作为后端,MySQL作为数据库,但前端每次请求都会从MySQL数据库中读取数据,而MySQL数据库的数据是存储于服务器磁盘中,所以响应速度有一定影 ...
- elmentui表单重置初始值问题与解决方法
背景 在做管理台项目时,我们会经常使用到表单+表格+弹窗表单的组合,以完成对数据的增.删.查.改. 在vue2+elementui项目中,使用弹窗dialog+表单form,实现对数据的添加和修改. ...
- 6. 用Rust手把手编写一个wmproxy(代理,内网穿透等), 通讯协议源码解读篇
用Rust手把手编写一个wmproxy(代理,内网穿透等), 通讯协议源码解读篇 项目 ++wmproxy++ gite: https://gitee.com/tickbh/wmproxy githu ...
- 9.1 运用API创建多线程
在Windows平台下创建多线程有两种方式,读者可以使用CreateThread函数,或者使用beginthreadex函数均可,两者虽然都可以用于创建多线程环境,但还是存在一些差异的,首先Creat ...
- vue上通过krpano.js实现360全景图
首先贴出一些XML对应的函数,文件内容都有注释说明, 前端代码读取xml文件代码 // 初始化 window.embedpano({ xml: 0, target: 'pano', html5: 'o ...
- P3214 [HNOI2011] 卡农 题解
感觉不是很麻烦,可能就组合排列转化绕一点... 抽象化题意 给定 \(n\) 个元素,从中选出 \(m\) 个集合,要求: 集合不为空,集合里不能有相同的元素 \(m\) 个集合都互不相同 所有元素被 ...
- DS18B20初始化-读-写-温度转换
DS18B20 (一)初始化 (二)读字节 (三)写字节 (四)温度转换 1获得数据 2转换数据 (一)初始化 初始化时序: 数据线先拉到高电平,稍作延时即可(刚开始是高电平还是低电平芯片手册上其实不 ...
- 谈谈流计算中的『Exactly Once』特性
本文翻译自 streaml.io 网站上的一篇博文:"Exactly once is NOT exactly the same" ,分析了流计算系统中常说的『Exactly Onc ...
- Safepoints: Meaning, Side Effects and Overheads(译文)
Safepoints: Meaning, Side Effects and Overheads (安全点:含义.副作用和开销) 去年,我一直在进行有关profiling以及JVM运行时/执行的一些讨论 ...