Version 4 of A little 6to4 calculator

Updated 2005-04-26 13:12:07 by rmax

rmax - April 2005

This little tool takes a list of IPv4 addresses on the command line, and calculates the respective IPv6 address prefixes for the 6to4 network.

Example usage:

 $ 6to4 10.0.0.1 192.168.22.33 
 10.0.0.1 -> 2002:a00:1::
 192.168.22.33 -> 2002:c0a8:1621::

 proc 6to4 {addr} {
    set octets [split [string trim $addr] .]
    if {[llength $octets] != 4} {
        return -code error \
            "\"$addr\" does not consist of 4 octets separated by dots"
    }
    foreach octet $octets {
        if {![string is integer $octet] || $octet < 0 || $octet > 255} {
            return -code error "\"$octet\" is not a valid octet"
        }
    }
    foreach {a b} $octets {
        lappend words [expr {($a<<8) | $b}]
    }
    eval [linsert $words 0 format "2002:%x:%x::"]
 }

 foreach v4addr $argv {
    catch {6to4 $v4addr} v6addr
    puts "$v4addr -> $v6addr"
 }

[ Category Internet ]