Git Product home page Git Product logo

demo-ip2location-c's Introduction

ip2location algorithm, C implemented

介绍

  • src/pack.php

将文本ip.txt转化为二进制ip.dat,每个ip段+定长的地理信息为一个entry(72字节)

  • src/test.c

测试文件打包是否正确

  • src/ip2location.c

从二进制ip.dat中查询特定IP,ip.dat是有序的连续分段,因此我们可以用二分查找的方式去找到给定IP所在的IP段,并查处对应地理信息

编译和使用

[tf@jp002 ip2location]$ ./make.sh 
[tf@jp002 ip2location]$ bin/ip2location 176.192.102.130 data/ip.dat 
start finding 176.192.102.130(2965399170)
index:222532, 202.197.123.1(3401939713) ~ 202.197.123.125(3401939837) <-
index:111266, 95.52.0.0(1597243392) ~ 95.55.255.255(1597505535) ->
index:166899, 146.71.0.0(2454126592) ~ 146.71.255.255(2454192127) ->
index:194715, 194.0.143.0(3254816512) ~ 194.0.143.255(3254816767) <-
index:180807, 185.23.204.0(3105344512) ~ 185.23.207.255(3105345535) <-
index:173853, 178.42.0.0(2989096960) ~ 178.43.255.255(2989228031) <-
index:170376, 165.87.0.0(2773942272) ~ 165.89.255.255(2774138879) ->
index:172114, 173.242.224.0(2918375424) ~ 173.243.31.255(2918391807) ->
index:172983, 175.192.0.0(2948595712) ~ 175.255.255.255(2952790015) ->
index:173418, 176.115.88.0(2960349184) ~ 176.115.95.255(2960351231) ->
index:173635, 176.227.240.0(2967728128) ~ 176.227.247.255(2967730175) <-
index:173527, 176.123.63.0(2960867072) ~ 176.123.63.255(2960867327) ->
index:173581, 176.126.60.0(2961062912) ~ 176.126.63.255(2961063935) ->
index:173608, 176.221.96.0(2967298048) ~ 176.221.127.255(2967306239) <-
index:173595, 176.206.0.0(2966290432) ~ 176.207.255.255(2966421503) <-
index:173588, 176.127.0.0(2961113088) ~ 176.127.255.255(2961178623) ->
index:173591, 176.198.0.0(2965766144) ~ 176.199.255.255(2965897215) <-
index:173590, 176.192.0.0(2965372928) ~ 176.197.255.255(2965766143) HIT!
ret=0, location=俄罗斯, CZ88.NET

demo-ip2location-c's People

Contributors

0x5446 avatar

Watchers

 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.