Search code examples
geoipmaxmindgeolitecity

How to use GeoLite City, how to obtain startIpNum and endIpNum


Alright i downloaded from http://dev.maxmind.com/geoip/legacy/geolite/ GeoLite City database.

The values are in the GeoLiteCity-Blocks.csv

startIpNum,endIpNum,locId
"16777216","16777471","17"

However i have no idea how to convert ips to these startIpNum and endIpNum range. I cant find on their site and they link to here

What is the algorithm to convert ip v4 into this ?

Thank you very much


Solution

  • It depends which programmation language you use.

    In php, you can use ip2long and long2ip to work with ips.

    string long2ip ( string $proper_address )
    The function long2ip() generates an Internet address in dotted format (i.e.: aaa.bbb.ccc.ddd) from the proper address representation.
    

    http://php.net/manual/en/function.long2ip.php

    Example with the ips you give: http://sandbox.onlinephpfunctions.com/code/3decd3d4818a02d65b9a80cf2dc1c70297b0d2d5