GithubHelp home page GithubHelp logo

iplocator's Introduction

基于qqwry.dat查找ip归属地的java程序

使用:

1. 直接调用(推荐,效率最高):

String ip = "202.108.22.5";
QQWryFile qqWryFile = QQWryFile.getInstance();
RandomAccessFile ipFile = qqWryFile.getIpFile();
QQWryRecord record = qqWryFile.find(ip, ipFile);
System.out.println(Utils.ipToStr(record.getBeginIP()));
System.out.println(Utils.ipToStr(record.getEndIP()));
System.out.println(record.getCountry());
System.out.println(record.getArea());

结果:

202.108.22.5
北京市
北京百度网讯科技有限公司联通节点

2. PostgreSQL:

  1. 在pg数据库里新建数据名为 ipsdb 的数据库(如需其他名字,在PostgreSQL.java文件内改相应的配置)
  1. 调PostgreSQL.java里的storage方法,把ip库存进pg数据里
  2. 查询:select * from ips where ip_start <= inet '202.108.22.5' and ip_end >= inet '202.108.22.5';

3. mongodb:

  1. 在pg数据库里新建数据名为 ipsdb 的数据库(如需其他名字,在MongoDB.java文件内改相应的配置)
  1. 调MongoDB.java里的storage()方法,把ip库存进mongo数据里
  2. 先把ip按Utils文件里的ipToLong变成长整型,然后再去查:
    db.ips.find({ip_start : {$lte : NumberLong(3396077979)}, ip_end : {$gte : NumberLong(3396077979)}})

4. mysql:

  1. 在pg数据库里新建数据名为 ipsdb 的数据库(如需其他名字,在MySQL.java文件内改相应的配置)
  1. 调MySQL.java里的storage()方法,把ip库存进mysql数据里
    select * from ips where ip_start <= inet_aton('202.108.22.5') and ip_end >= inet_aton('202.108.22.5');

参考资料:

  1. 纯真IP数据库格式详解:http://lumaqq.linuxsir.org/article/qqwry_format_detail.html
  2. ruby程序的实现:https://github.com/hide2/ruby-qqwry
  3. java程序的实现:https://github.com/talentyao/IPLocator
  4. 纯真IP数据库qqwry.dat更新:http://www.cz88.net/ 右上角有个IP数据库下载,里面的说明文件里说明了更新的方法。

iplocator's People

Contributors

talentyao 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.