#!/bin/bash
# License http://creativecommons.org/licenses/by-nc-sa/3.0/
# Free IPv6 Connectivity for Servers over net6.at
# Script by Philipp 'TamCore' B. (http://tamcore.eu)

echo "Free IPv6 Connectivity for Servers over net6.at"

if [ "$UID" != "0" ] ; then
        echo "You must be root!"
        exit 1
fi
if [ "$1" ] ; then
        DEV="$1"
else
	echo "Usage: $0 <interface>"
	echo "NOTE: <interfaces> must have an valid IPv4 Address!"
        exit 1
fi

IP=`ifconfig $DEV | grep -v inet6 | grep inet | awk -F: '{print $2}' | awk '{print $1}'`

if [ "$IP" == "" ] ; then
	echo "No IPv4 on $DEV found! exiting..."
	exit 1
fi

IP6=`printf $IP | sed 's/\./ /g'`
IP6=`printf "2002:%02x%02x:%02x%02x::1" $IP6`
ip -6 route flush dev 6to4 2>/dev/null
ip link set dev 6to4 down 2>/dev/null
ip tunnel del 6to4 2>/dev/null
ip tunnel add 6to4 mode sit ttl 64 remote any local $IP
ip link set 6to4 up
ip -6 addr add $IP6/48 dev 6to4
ip -6 route add 2000::/3 via ::192.88.99.1 dev 6to4 metric 1
echo "Your IPv4 IP: $IP"
echo "Your IPv6 IP: $IP6"


