Version 2 of A little 6to4 calculator

Updated 2005-04-26 13:03:33 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:001::
 192.168.22.33 -> 2002:c0a8:1621::

 package require Tcl

 # calculate the 6to4 prefix for a given IPv4 address
 proc 6to4 {addr} {
    set addr [split [string trim $addr] .]
    if {[llength $addr] != 4} {
        return -code error \
            "\"$addr\" does not consist of 4 octets separated by dots"
    }
    foreach octet $addr {
        if {![string is integer $octet] || $octet < 0 || $octet > 255} {
            return -code error "\"$octet\" is not a valid octet"
        }
    }
    eval [linsert $addr 0 format "2002:%x%02x:%x%02x::"]
 }

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

[ Category Internet ]