Skip to content

Instantly share code, notes, and snippets.

@uriel1998
Created October 11, 2013 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uriel1998/6942365 to your computer and use it in GitHub Desktop.
Save uriel1998/6942365 to your computer and use it in GitHub Desktop.
Present any network "logon page" with network connect.
#!/bin/bash
# I have both the interface and external ip echoed to conky, so I had a version of this script already.
# This version is for autolaunch, so it presents a nice popup browser if it can't resolve its own IP
# address (such as for places that have public wifi and "click here".
# This version is designed to start up with the GUI interface, not as a system
# service! So if you use it with WICD, do not do it as an ifup command, otherwise
# you will have issues because it can't launch the browser.
function getextip {
ext_ip=$(wget -q -O - checkip.dyndns.org |grep "Current IP Check"| sed -e 's/[^[:digit:]|.]//g')
len_ext_ip=${#ext_ip}
# Yes, I am only testing IPv4 here.
status=0
if [ $len_ext_ip -lt 16 ]; then
if [ $len_ext_ip -gt 7 ]; then
status=1
fi
fi
}
#main function
ext_ip=$(echo "0.0.0.0")
interface=$(netstat -nr | grep -m 1 ^0.0.0.0 | awk -F " " '{print $8}')
# Response should be tun[0-9], wlan[0-9], eth[0-9]
# You can use a more complex case statement here if you like
if [ "$interface" != "" ]; then
getextip
if [ $status = 0 ]; then
# I use midori here because it's the lightest weight browser that can handle
# all the different forms and such that I've encountered for public wifi login
# otherwise I'd use elinks. Ah well.
midori http://stevesaus.com &
sleep 60
# Alternately, get rid of the ampersand and have the script wait for you to close the browser.
getextip
if [ "$status" = "0" ]; then
ext_ip=$(echo "0.0.0.0")
fi
fi
fi
# This could also be where you insert a command to bring up your VPN if $ext_ip != 0.0.0.0 :)
echo "$interface"
echo "$ext_ip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment