Alexander Newald wrote:

I have a table with only ips in it. I want to get all networks the ips
belong to:

If you always use 24 bit netmasks, then the other solutions given should work just fine. If you're working with arbitrary sized networks though, you might want to store the IP addresses as their full 32-bit values and do the standard network math on them to find their networks, etc.

Basically, you convert 192.168.1.13 to 192 * 2^24 + 168 * 2^16 + 1 * 2^8 + 13 = 3232235789.

To get the network, in a 24 bit netmask, take the value binary ANDed against 2^32 - 2^8 (leaving high 24 bits). You can probably do most of this math within MySQL itself, and the values it returns will be in decimal for your values but they're easily sorted, etc. and conversion for traditional dotted-quad values isn't too difficult either.

Just FYI ... :) Oh, QUERY.

--
Michael T. Babcock
C.T.O., FibreSpeed Ltd.
http://www.fibrespeed.net/~mbabcock



---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



Reply via email to