Retrieval of IP's yields multiple rows

I’m trying to get an id for a row in a lookup table based on an ip address. All ip’s are stored as varbinaries. The lookup table has ip ranges (start and end) and countries associated with the range. When I run the following query, I’m getting multiple rows. (1219006512 is the varbinary of an ip I’m trying to relate to the lookup table). Query follows:

SELECT * FROM lookup WHERE ('1219006512' >= start and '1219006512'<=end);

Here’s a screenshot of the results of the query run in phpmyadmin:

I get the same results with
SELECT * FROM lookup WHERE ('1219006512' between start and end);

Can someone explain why I’m getting multiple rows returned?

Still getting multiple rows, neither of which is correct. At least the original query got one correct row.

The fields start and end contain the results of inet_aton(start_ip) and inet_aton(end_ip). The value I’m testing is the result of inet_aton(user’s ip). All the ip fields are varbinary(16). When I ran the original query in mysql from the command line I got the same result set:

Much different results from the original results from phpmyadmin but still not right as it gets multiple rows. What am I doing wrong?

https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_inet-aton

Sponsor our Newsletter | Privacy Policy | Terms of Service