【geoip】geoip操作GeoLiteCity.dat
来源:互联网 发布:linux nano vim 编辑:程序博客网 时间:2024/06/05 18:52
如何下载GeoLiteCity.dat.gz
下载:wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
解压:gunzip GeoLiteCity.dat.gz
jiayi@ubuntu:~$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz --2015-12-22 18:10:24-- http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzResolving geolite.maxmind.com (geolite.maxmind.com)... 141.101.114.190Connecting to geolite.maxmind.com (geolite.maxmind.com)|141.101.114.190|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 12328291 (12M) [application/octet-stream]Saving to: ‘GeoLiteCity.dat.gz’100%[===================================================================================================================>] 12,328,291 739KB/s in 23s 2015-12-22 18:10:54 (530 KB/s) - ‘GeoLiteCity.dat.gz’ saved [12328291/12328291]jiayi@ubuntu:~$ lsDesktop Documents Downloads examples.desktop GeoLiteCity.dat.gz Music Pictures Public soft Templates tool Vide
使用Geoip操作GeoLiteCity.dat
TEST
public class IPSearchService { public static void main(String[] args) throws IOException { String geoLiteCityFilePath = Thread.currentThread().getContextClassLoader().getResource("GeoLiteCity.dat").getPath(); LookupService lookupService = new LookupService(geoLiteCityFilePath,LookupService.GEOIP_MEMORY_CACHE); String ip = "218.28.2.111"; InetAddress inetAddress = InetAddress.getByName(ip); System.out.println("areaCode:"+lookupService.getLocation(inetAddress).area_code); System.out.println("city:"+lookupService.getLocation(inetAddress).city); System.out.println("countryCode:"+lookupService.getLocation(inetAddress).countryCode); System.out.println("countryName:"+lookupService.getLocation(inetAddress).countryName); System.out.println("postalCode:"+lookupService.getLocation(inetAddress).postalCode); System.out.println("region:"+lookupService.getLocation(inetAddress).region); System.out.println("dma_code:"+lookupService.getLocation(inetAddress).dma_code); System.out.println("latitude:"+lookupService.getLocation(inetAddress).latitude); System.out.println("longitude:"+lookupService.getLocation(inetAddress).longitude); System.out.println("metro_code:"+lookupService.getLocation(inetAddress).metro_code); }}结果:
areaCode:0city:ZhengzhoucountryCode:CNcountryName:ChinapostalCode:nullregion:09dma_code:0latitude:34.683594longitude:113.5325metro_code:0
POM
<properties> <geoip-api.version>1.2.15</geoip-api.version> </properties> <dependencies> <dependency> <groupId>com.maxmind.geoip</groupId> <artifactId>geoip-api</artifactId> <version>${geoip-api.version}</version> </dependency> </dependencies>
PS:可以将离线数据GeoLiteCity.dat读到redis里面,然后通过jedis操作,也许是更好的办法。
0 0
- 【geoip】geoip操作GeoLiteCity.dat
- geoip
- geoip
- GeoIP
- geoip设置
- AWStats扩展GeoIP
- python--geoip tool
- python 使用GeoIP
- bind-geoip编译使用说明
- Install GeoIP For Apache
- geoip PHP版本
- 安装GeoIP数据库
- nginx增加GeoIP模块
- Logstash过滤器--Geoip
- awstats上应用GeoIP
- 安装GeoIP数据库
- Logstash过滤器--Geoip
- Logstash模块之geoip
- break,continue,return三者之间的区别
- Android模糊bitmap的工具类
- Java8 Lambda表达式和流操作如何让你的代码变慢5倍
- 回归测试的精确化
- Ubuntu 13.10 64bit 不能运行 32bit的软件
- 【geoip】geoip操作GeoLiteCity.dat
- 你对做水晶头还有疑问吗?
- BLE发送接收任意字节数据
- H264的I/P/B帧类型判断
- swift ios转场动画详解
- 网络爬虫——爬取糗事百科笑料段子
- 创建实例失败 state error
- 设计模式之适配器
- OC学习篇之-----类目·延展·协议之--类目