5 messages in com.mysql.lists.mysqlRe: IP address to searchable number
FromSent OnAttachments
Scott Haneda13 Oct 2004 21:33 
Gary Richardson13 Oct 2004 21:40 
Dan Nelson13 Oct 2004 21:42 
James Weisensee13 Oct 2004 23:28 
Jigal van Hemert14 Oct 2004 00:01 
Subject:Re: IP address to searchable number
From:Jigal van Hemert (jig@spill.nl)
Date:10/14/2004 12:01:50 AM
List:com.mysql.lists.mysql

From: "Scott Haneda" <lis@newgeo.com>

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.