selva24
selva24

Reputation: 11

IP address representation in the Maxmind Geolitecity database

I have the Maxmind Geolitecity database in a Mysql database.

I could see field like startIpNum and endIpNum.

The values for those fields are like this: 16777216 for startIpNum and 16777471for endIpNum`.

My ip is 115.184.126.186, how can I convert my ip to match the startIpNum or endIpNum?

Upvotes: 1

Views: 1100

Answers (4)

arsenal
arsenal

Reputation: 24174

Try converting it like this-

SELECT INET_ATON("115.184.126.186");

Upvotes: 0

rrapuya
rrapuya

Reputation: 298

try something like this :

<?php 
 $ipadd="115.184.126.186";
 $ips = explode(".",$ipadd);
 $x=($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
 echo $x;
?>

just modify this one into a function..

here is the result of the code

Upvotes: 0

jishi
jishi

Reputation: 24624

Either use inet_aton() as suggested by lmz, or do it in php using:

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

Note that this function returns an signed integer, meaning ranging from − 2,147,483,648 to 2,147,483,647, and I think the maxmind geoip database uses unsigned ints (0-4,294,967,295?) so you need to add 2,147,483,647 to it (2^31-1)

Upvotes: 2

lmz
lmz

Reputation: 1580

Try the inet_aton function in MySQL.

Upvotes: 1

Related Questions