Experts Round Table Network

Webservers => Apache => Topic started by: CrYpTiC_MauleR on May 30, 2007, 03:50:18 PM



Title: IPv6 Logging
Post by: CrYpTiC_MauleR on May 30, 2007, 03:50:18 PM
http://www.loganalyzer.net/log-analyzer/ipv6-log-analysis.html shows how an IPv6 log entry would look like. Is there an option to enable this because I am trying to add IPv6 support for my web applications like banning script, log script etc. Also on same topic how do I convert an IPv4 address to an IPv6 address? Example 1.2.3.4 becomes ????:????:????:????:????:????:????:???? thanks!


Title: Re: IPv6 Logging
Post by: rdivilbiss on May 30, 2007, 05:15:40 PM
How do I convert an IPv4 address to an IPv6 address? Example 1.2.3.4 becomes ????:????:????:????:????:????:????:???? thanks!

I don't know but I'm afraid we are all going to have to learn that very soon.  Ergo, I am monitoring so I can piggy back off the answer to your question.


Title: Re: IPv6 Logging
Post by: CrYpTiC_MauleR on May 30, 2007, 07:48:26 PM
I think I figured it out =oD

68.45.98.34

first take each part and consider it a decimal value and then convert it to hex so
68 would be 44
45 would be 2D
98 would be 62
34 would be 22

Then IPv6 IP equivalent would be

442D:6222 in short form and 0:0:0:0:0:0:442D:6222 in long form or could be 442D:6222:0:0:0:0:0:0 don't know that for sure yet, will read up more in the RFC.


Title: Re: IPv6 Logging
Post by: VGR on May 31, 2007, 10:35:06 AM
the RFC 1897 defines this schema to integrate existing ip v4 addresses in a v6 format :

(http://livre.point6.net/images/9/91/CS215.gif)


Title: Re: IPv6 Logging
Post by: CrYpTiC_MauleR on May 31, 2007, 12:01:48 PM
Code
Language: php (GeSHi-highlighted)
<?php
/*
* Copyright (C) 2007 CrYpTiC MauleR <http://www.expertsrt.net/images/cm_email.gif>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*/

 
/*
* @desc    Converts An IPv4 IP Address To An IPv6 IP Address
* @param   str $ip
* @return  str
*/

function ipv4_to_ipv6($ip)
{
   if (-1 !== ip2long($ip)) /* Check If Valid IPv4 IP */
   {
       $octets = explode('.', $ip);
       $ip = '0:0:0:0:0:0:';
       foreach ($octets as $octet => $value)
       {
           if (2 === $octet)
           {
               $ip .= ':';
           }                  
           $ip .= ltrim(dechex($value), '0'); /* Remove Leading Zeroes */
       }
       return $ip;
   }
   return false;
}
 
?>

I made the above to convert an IPv4 IP to an IPv6 IP with leading zero compression. Also used http://www.php.net/manual/en/function.ip2long.php#71957 to make IPv6 IPs long so can insert into database more easily and do range checks etc. I'm still not sure if I did the above conversion correctly since I have yet to check out the RFC, so please correct me if I have not. Thanks.


Title: Re: IPv6 Logging
Post by: CrYpTiC_MauleR on June 02, 2007, 05:51:21 PM
the IPv6 ip2long function linked above is incorrect. It does not correctly convert an IPv6 address into long format. I have had to make my own to properly convert it and handle the large address space. Basically FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF to long format should equal 340282366920938463463374607431768211455 NOT 2147483647 as the incorrect function is outputting.