List:General Discussion« Previous MessageNext Message »
From:Matthias Pigulla Date:May 12 1999 8:46pm
Subject:Packing IP addresses
View as plain text  
Hi folks,

I want to pack IP addresses for I have to store a lot of them in a
database ;-)

Does anyone know a shorter solution than:

-MySQL---
select
 (substring_index(substring_index('255.255.255.255', '.', 1), '.', -1)
<< 24) +
 (substring_index(substring_index('255.255.255.255', '.', 2), '.', -1)
<< 16) +
 (substring_index(substring_index('255.255.255.255', '.', 3), '.', -1)
<< 8)  +
 (substring_index(substring_index('255.255.255.255', '.', 4), '.', -1))
as ipshort
-MySQL---

Which would save all from 1.1.1.1 to 255.255.255.255 in an unsigned INT
type field.

Matthias
-- 
   w e b f a c t o r y | matthias pigulla
      www.webfactory.de  mp@stripped
Thread
Packing IP addressesMatthias Pigulla13 May
  • Re: Packing IP addressesUnknown Sender13 May
    • Re: Packing IP addressesDr Eberhard W Lisse13 May
      • Re: Packing IP addressesBen Kirkpatrick13 May
        • Re: Packing IP addressesUnknown Sender13 May
      • Re: Packing IP addressesunknown13 May
  • Re: Packing IP addressesSasha Pachev13 May
  • Re: Packing IP addressesSteve Lihn13 May