-
-
Save eugeneai/3993265 to your computer and use it in GitHub Desktop.
tunnelbroker.net automatic tunnel IP update and tunnel setup (on Mac OS X)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### This script is published by Philipp Klaus <[email protected]> | |
#### on <http://blog.philippklaus.de/2011/05/ipv6-6in4-tunnel-via-hurricane-electric-tunnelbroker-net-automatic-ip-update-on-mac-os-x/> | |
#### It is originally by freese60 and modified by limemonkey. | |
#### Found on <http://www.tunnelbroker.net/forums/index.php?topic=287.0> | |
### Uncomment this line to debug the script: | |
#set -x | |
####################################################################### | |
#### Config start | |
### | |
### This configuration file must set the following variables: | |
### MYIF, DEVNAME, LOCAL_IPV4, EXTERNAL_IPV4, | |
### HEUSER, HEPASS, HETUNNEL, | |
### HESERVER4END, HESERVER6END and HECLIENT6END | |
#MYIF="en1" # en1 = Airport, en0 = Ethernet | |
MYIF=`netstat -f inet -r | grep default | tr -s ' ' | cut -d ' ' -f 6` # autodetect | |
DEVNAME='gif0' | |
# LOCAL_IPV4=`ifconfig #MYIF | grep 'inet ' | tr -s ' ' | cut -d ' ' -f 2` # if you need to use your public ip address, use LOCAL_IP=$EXTERNAL_IPV4 instead | |
LOCAL_IPV4=`ifconfig $MYIF |grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` | |
#EXTERNAL_IPV4=`curl -s "http://www.networksecuritytoolkit.org/nst/cgi-bin/ip.cgi"` | |
EXTERNAL_IPV4=`curl -s "http://v4.ipv6-test.com/api/myip.php"` | |
# one more site, to get your external IPv4 IP: http://v4.ipv6-test.com/api/myip.php | |
#EXTERNAL_IPV4='AUTO' # ← If you don't want to get use www.networksecuritytoolkit.org but tunnelbroker.net, then set it to AUTO | |
HEUSER='dn6483m67d411ba0.26906527' # hash from the website, "UserID" | |
HEPASS='32f325019357278d1da3ba06887fa6f1' # hash: echo -n MyPass|md5 | |
HETUNNEL=12056 # from the website, "Global Tunnel ID" | |
### other settings from the website (the tunnel settings): | |
HESERVER4END='216.66.80.30' | |
HESERVER6END=2001:470:1f0a:3333::1 | |
HECLIENT6END=2001:470:1f0a:3333::2 | |
HE64PREFIX=2001:470:1f0b:3333:: | |
MYCUSTOMADDRESS=${HE64PREFIX}1:1 | |
####################################################################### | |
#### Starting the actual script | |
echo "Please enter your user account password. It is needed to set up the IPv6 tunnel." | |
sudo echo "Gained superuser permissions" | |
if [ $? == 1 ]; then echo "Sorry! You need to provide your password in order to set up the tunnel."; exit 1; fi | |
echo "Remove previous tunnel (ignore any errors)" | |
sudo ifconfig $DEVNAME down | |
sudo ifconfig $DEVNAME inet6 $MYCUSTOMADDRESS prefixlen 128 delete | |
sudo ifconfig $DEVNAME inet6 $HECLIENT6END $HESERVER6END prefixlen 128 delete | |
sudo route delete -inet6 default -interface $DEVNAME | |
sudo ifconfig $DEVNAME deletetunnel | |
echo "Removed the previous tunnel. Will continue to set up the tunnel in 5 seconds..." | |
for i in {5..1}; do echo "$i"; sleep 1; done | |
echo "Updating your IPv4 tunnel endpoint setting on the Hurricane Electric Website." | |
# And instead of determining the external IPv4 address on your own, you can also set the param ip to AUTO. | |
curl -k -s "https://ipv4.tunnelbroker.net/ipv4_end.php?ip=$EXTERNAL_IPV4&pass=$HEPASS&apikey=$HEUSER&tid=$HETUNNEL" | |
# One more API of the tunnelbroker.net site is: https://username:[email protected]/tunnelInfo.php[?tid=tunnel_id] which returns an XML output | |
sleep 1 | |
echo "Setting up the tunnel with the new settings now ." | |
sudo ifconfig $DEVNAME create | |
sudo ifconfig $DEVNAME tunnel $LOCAL_IPV4 $HESERVER4END | |
sudo ifconfig $DEVNAME inet6 $MYCUSTOMADDRESS prefixlen 128 | |
sudo ifconfig $DEVNAME inet6 $HECLIENT6END $HESERVER6END prefixlen 128 | |
sudo route -n add -inet6 default $HECLIENT6END | |
# We now provide the user with information if the tunnel has ben set up successfully: | |
sleep 1 | |
echo "The external IPv6 is now set to `curl -s 'http://v6.ipv6-test.com/api/myip.php'`." | |
echo "The external IP of your default connection is now set to `curl -s 'http://v4v6.ipv6-test.com/api/myip.php'`." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment