Skip to content

Instantly share code, notes, and snippets.

@itay-grudev
Last active March 19, 2021 19:53
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save itay-grudev/d3d4eb0dc4e239d96c84 to your computer and use it in GitHub Desktop.
Save itay-grudev/d3d4eb0dc4e239d96c84 to your computer and use it in GitHub Desktop.
BT WiFi Maintain Connectivity Script

BT WiFi Maintain Connectivity Script

Usage

btauth --user USER_OR_EMAIL --pass PASSWORD # To Authenticate with the BT WiFi
btmaintain --user USER_OR_EMAIL --pass PASSWORD # To maintain a connection and re-authenticate automatically
nohup btmaintain --user USER_OR_EMAIL --pass PASSWORD 2>&1 >/dev/null & # Same as above but ran in background

This will check whether you lost connectivity by pinging google.com every 1 second. If you are not it will check whether the SSL certificate of google.com had been replaced with a BT WiFi certificate and re-authenticate you via btauth.

Installation

Download or copy both scripts to /usr/local/bin and give them execute permissions:

mkdir -p /usr/local/bin
curl -sSL https://goo.gl/2gto0U > /usr/local/bin/btauth
chmod +x /usr/local/bin/btauth
curl -sSL https://goo.gl/07sNF1 > /usr/local/bin/btmaintain
chmod +x /usr/local/bin/btmaintain

License

BTAuth Copyright (C) 2015 Itay Grudev

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See http://www.gnu.org/licenses/ for the full text of the GNU General Public License.

#!/bin/bash
# BTAuth Copyright (C) 2015 Itay Grudev
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# See http://www.gnu.org/licenses/ for the full text of the GNU
# General Public License.
function usage {
echo 'Usage:' $(basename $0) '--user USER --pass PASS [-h] [--help]'
exit 2
}
userset=0
passset=0
for i
do
parsed=0
case "$i"
in
-h|--help)
usage;;
--user)
userset=1
BTUSER="$2"; shift;
shift;;
--pass)
passset=1
BTPASS="$2"; shift;
shift;;
--)
shift;
break;;
esac
done
if [ $userset == 0 ]; then usage; fi
if [ $passset == 0 ]; then usage; fi
curl --data "username=$BTUSER&password=$BTPASS&submit=Login" https://www.btopenzone.com:8443/tbbLogon
#!/bin/bash
# BTAuth Copyright (C) 2015 Itay Grudev
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# See http://www.gnu.org/licenses/ for the full text of the GNU
# General Public License.
while true; do
ping -c 1 -t 1 google.com 2>/dev/null >/dev/null
if [ $? == 2 ]; then
echo | openssl s_client -showcerts -status -connect google.com:443 2>/dev/null | openssl x509 -inform pem -noout -subject | grep CN=www.btwifi.com 2>/dev/null >/dev/null
if [ $? == 0 ]; then
echo 'Logging in'
btauth $@
fi
fi
sleep 1
done
@jameswardzala
Copy link

This doesn't work with BT-WIFI Fon as there are radio buttons

@gingerbeardman
Copy link

gingerbeardman commented Jul 13, 2016

@jameswardzala the default radio button is for BT Broadband user, which the login page assumes if you do not tell it otherwise. And so this script will log in as that.

If you want a different radio button you'll have to add that option to the curl data string.

BT Broadband
&provider=tbb

BT Business Broadband
&provider=business

BT Wi-fi
&provider=btoz

FON
&provider=fon (FON also expects fields USERNAME and PASSWORD in capitals)

Of course you need to call the script with your real login username and password, properly escaped to work on a command line.

Logout URL for testing is https://www.btopenzone.com:8443/accountLogoff/home

@Vinblastine
Copy link

I'm sorry to say that I could not get this to work. I have been trying to use the 'BT Wifi' selection. I added the "&provider=btoz" to the beginning and to the end of the curl data string but I just could not get it to work. There was another script by https://gist.github.com/sscarduzio/05ed0b41d6234530d724 which I have also tried to use with the '&provider=btoz' but to no avail. I am still a bit of a beginner with scripting and linux. I have tried my best to troubleshoot it but I just seem to be getting nowhere. Is there anyway to get any error messages or log to examine what is going wrong with the curl string?

@itay-grudev
Copy link
Author

itay-grudev commented Aug 18, 2019 via email

@Vinblastine
Copy link

Thanks for getting back to me. I managed to get the other script I mentioned working which uses wget rather than curl. You were right, the form had changed and by inspecting the webpage it could be seen that the login url was different for BT WIFI.
BT broadband logins still use 'https://www.btopenzone.com:8443/tbbLogon' however there was a new URL: 'https://www.btwifi.com:8443/ante' for the BT Wifi logins.

@itay-grudev
Copy link
Author

itay-grudev commented Aug 18, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment