Re: function to compare ip addr to a ip range>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, October 13, 2005 9:26 am, Bosky, Dave wrote:
> Does anyone have a function that will check if an ip address falls
> with
> a starting/ending ip address range>>

If you are using PostgreSQL, it has a built-in IP address data type
which almost for sure does this. :-)

Maybe what you want to do is just convert the IP to an integer.

function ipd($ip){
  list($a, $b, $c, $c) = explode('.', $ip);
  $ipd = $a * 0x1000000 + $b * 0x10000 + $c * 0x100 + $d;
  return $ipd;
}

Now you can just compare idp() of any IP addresses to see if they are
in a 'range'

There's probably a better way.

And you should probably use bit-shifting operators (<< and >>) insted
of my * 0x1000000 method, as it might be faster.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux