Advertisement

07.15.2008 at 06:07PM PDT, ID: 23568190
[x]
Attachment Details

MySQL:  How to efficiently compare with a binary mask

Asked by willsherwood in MySQL, PHP and Databases

What field types and compare "equation" is best to use for the following comparison, equivalent to the standard form like 10.10.10.0/24
(I use PHP)

Given an incoming IP address  $ThisIPAddress, converted to 32-bit integer,
is it in tblBlockAddresses (IPBase, Mask)

SELECT ID FROM tblBlockAddresses WHERE ($ThisIPAddress AND Mask)=(IPBase AND Mask)

where AND should be a bitwise AND
Note that I'd like to mask both before comparing

thanks
Start Free Trial
[+][-]07.15.2008 at 07:06PM PDT, ID: 22012772

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 07:06PM PDT, ID: 22012776

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MySQL, PHP and Databases
Sign Up Now!
Solution Provided By: matthewstevenkelly
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628