Giter VIP home page Giter VIP logo

qqwry's Introduction

qqwry

纯真IP地址库qqwry.dat解析代码 使用两种方式实现:

  • 使用内存映射文件方式读取(位于com.difeng.qqwry1包下)
  • 使用byte数组读取(位于com.difeng.qqwry2包下)

两种实现,使用方法一致:

final IPLocation ipLocation = new IPLocation(filePath);
Location loc = ipl.fetchIPLocation("182.92.240.50");
System.out.printf("%s %s",loc.country,loc.area);

两种实现方式都不用重启就可实现升级qqwry.dat文件,只要用新文件将旧文件覆盖,程序会自动检查文件最后修改时间,若最后修改时间大于上一次时间,则重新加载数据文件,通过修改IPLocation类中的常量enableFileWatch=true来开启,默认是关闭的。

建议

不需要热升级IP数据库文件时,使用方式二,效率较高
此外,使用两种方式都可以,效率上没有太大差别

新添转化功能,将原文件格式转换为新格式,新格式比较简单去掉了原来的重定向标志,国家和地区单独存放,索引里分别记录的国家和地区的地址。

新格式如下:

+----------+
|   文件头       |  (8字节) 
+----------+
|   记录区       |  (不定长)
+----------+
|   索引区       |  (大小由文件头决定)
+----------+
文件头:
+------------------------------+-----------------------------+
| first index position(4 bytes)|last index position(4 bytes) | 
+------------------------------+-----------------------------+
记录区:
+------------------+----------+------------------+----------+-----
| country1(n bytes)|\0(1 byte)| country2(n bytes)|\0(1 byte)|...
+------------------+----------+------------------+----------+-----
+------------------+----------+------------------+----------+-----
| area1(n bytes)   |\0(1 byte)| area2(n bytes)   |\0(1 byte)|...
+------------------+----------+------------------+----------+-----
索引区:
+------------+-------------------------+------------------------+
|ip1(4 bytes)|country position(3 bytes)| area position(3 bytes) |...
+------------+-------------------------+------------------------+

转换方法:

final IPFileConvertor convertor = new 
IPFileConvertor(IPFileConvertor.class.getResource("/qqwry.dat").getPath(),"./qqwry.dat");
convertor.convert();

新格式使用方法和之前一致,使用com.difeng.convert包下的解析类IPLocation解析即可。

qqwry's People

Contributors

difeng avatar

Watchers

James Cloos avatar lslab avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.