Skip to content

Instantly share code, notes, and snippets.

@lehmannro
Created June 27, 2011 07:12
Show Gist options
  • Save lehmannro/1048432 to your computer and use it in GitHub Desktop.
Save lehmannro/1048432 to your computer and use it in GitHub Desktop.
University of Potsdam WLAN-over-VPN wrapper
#!/bin/sh
# University of Potsdam WLAN-over-VPN wrapper
VPNUSER=$(read -p "Username:")
#VPNUSER=johndoe
WLANIFACE=wlan0
VPNIFACE=zeik.tun0
# kill all remaining Cisco AnyConnect VPNs
pkill openconnect
[ "x$1" = "xstop" ] && exit 1
# determine hostname
essid=`iwgetid --raw $WLANIFACE`
case $essid in
"Uni-WLAN-Wohnheim") host=wh group=wohnheim-wlan ;;
"Universitaet Potsdam ZEIK") host=wlan group=WLAN ;;
*) host=ssl group=SSLVPN
ping -c 1 sslvpn.uni-potsdam.de || exit 1 ;;
esac
host=${host}vpn.uni-potsdam.de
# connect to the VPN
echo "Connecting to $host:$group..."
openconnect $host --user=$VPNUSER --authgroup=$group \
--verbose --syslog --background --interface=$VPNIFACE \
&& echo "Connected!"
# route all connections thru the VPN interface
if [ "$host" != "ssl" ]; then
route add default dev $VPNIFACE
else
route add uni-potsdam.de dev $VPNIFACE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment