[racktables-users] Re: IP 4 calculation

  • From: Jan Ulferts <Jan.Ulferts@xxxxxxxx>
  • To: "racktables-users@xxxxxxxxxxxxx" <racktables-users@xxxxxxxxxxxxx>
  • Date: Fri, 18 Nov 2011 00:10:07 +0100

The MySQL-Way is INET_NTOA and INET_ATON.

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

These functions will do the math John descripted.

Cheers,
Jan

On Do, 2011-11-17 at 23:06 +0100, John Lockard wrote:
> http://sqlserver2000.databases.aspfaq.com/how-should-i-store-an-ip-address-in-sql-server.html
> http://php.net/manual/en/function.long2ip.php
> 
> Basically you're using division with remainders.
> 
> 167908620 / (256*256*256) = 10 R 136460
> 136460 / (256*256) = 2 R 5388
> 5338 / (256) = 21 R 12
> 
> 10.2.21.12
> 
> or
> 
> ip1 = ip / 16777216 
> ip =  ip % 16777216 
> ip2 = ip / 65536 
> ip =  ip % 65536 
> ip3 = ip / 256 
> ip =  ip % 256 
> ip4 = ip 
> 
> -John
> 
> On Thu, Nov 17, 2011 at 09:04:39PM +0000, Lokkerbol, Cliff wrote:
> > Hi,
> > 
> > I am in the process of writing some SQL to generate reports from 
> > Racktables. My question is how to I calculate the IP from the IP column. So 
> > example how to I get from 167908620 to 10.2.21.12?
> > 
> > Thanks
> > Cliff
> > This message was created by:
> > Cliff Lokkerbol - System Support Specialist - Innovation I.T Services
> > "Simply put, it is possible to have convenience if you want to tolerate 
> > insecurity; but if you want security, you must be prepared for 
> > inconvenience."
> > 
> > 
> > ________________________________________________________________________
> > Any opinions expressed in this email are those of the individual and not 
> > necessarily the company. The contents of this email and any attachments are 
> > confidential to The Innovation Group PLC and are solely for use by the 
> > intended recipient at the email address to which it has been addressed.
> > 
> > This email and any attachments may not be disclosed to or used by anyone 
> > other than the intended recipient, nor may it be copied in any way.  If you 
> > have received this email in error, please forward a copy of this email to 
> > itsupport@xxxxxxxxxxxxxxxxxxxxxxx and then delete it from your system.
> > 
> > The Innovation Group PLC: Registered in England 3256771
> > Registered Office: Yarmouth House 1300 Parkway Solent Business Park 
> > Whiteley Hampshire PO15 7AE UK
> > http://www.innovation-group.com
> > 
> > This email and any attachments has been swept for computer viruses. Neither 
> > The Innovation Group PLC nor the sender accept any responsibility for 
> > computer viruses once this email has been transmitted.
> 

Other related posts: