Furkan Gözükara
Furkan Gözükara

Reputation: 23870

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

Upvotes: 0

Views: 1028

Answers (2)

Camila Burne
Camila Burne

Reputation: 256

If you were using Python, you could use

>>> import socket, struct
>>> socket.inet_ntoa(struct.pack('!L', 16777216))
'1.0.0.0'

to convert from integer to IP string.

Upvotes: 0

zeflex
zeflex

Reputation: 1527

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

Upvotes: 1

Related Questions