List:General Discussion« Previous MessageNext Message »
From:Jigal van Hemert Date:October 14 2004 7:02am
Subject:Re: IP address to searchable number
View as plain text  
From: "Scott Haneda" <lists@stripped>
> Any idea what I should convert a IP address into in order to be able to
> operate on it with simple greater than, less than and equal to math?

As a compromise between human readability and searchability you could store
the IP-address as a series of zero-padded numbers in a VARCHAR field:
012.008.197.010 -> 012.008.197.100

Now you can use string comparison operators such as >, <, =, BETWEEN and
even LIKE to see if the IP-address is in the range 12.8.* (from_ip LIKE
'012.008.%').
If you want to use normal IP-masks than you probably want to use unsigned
integer using the inet_aton and inet_ntoa functions as suggested by others.

Regards, Jigal.

Thread
IP address to searchable numberScott Haneda14 Oct
  • Re: IP address to searchable numberGary Richardson14 Oct
  • Re: IP address to searchable numberDan Nelson14 Oct
  • Re: IP address to searchable numberJames Weisensee14 Oct
  • Re: IP address to searchable numberJigal van Hemert14 Oct