Skip to content

Instantly share code, notes, and snippets.

@Steve-Tech
Last active August 22, 2020 01:24
Show Gist options
  • Save Steve-Tech/aef02836011ed84990a297a9783cdd7f to your computer and use it in GitHub Desktop.
Save Steve-Tech/aef02836011ed84990a297a9783cdd7f to your computer and use it in GitHub Desktop.
Python Telstra Air Connector
import requests
import re
session = requests.Session()
# This isn't your Telstra ID but rather the Fon credentials found in the Telstra Air app, you can also find this in the network tab of inspect element when logging in normally.
anid = "m61400000000@wifi.telstra.com"
anidpassword = ""
try: login = re.findall(r'<LoginURL>(.*)</LoginURL>', session.get("http://msftconnecttest.com/redirect").text)[0] # Get the Telstra Air login URL
except IndexError: print("Already Connected"); exit()
# Get the required parameters to login
nasid = re.findall(r'nasid=(.*)&amp;',login)[0]
ipaddr = re.findall(r'uamip=(.*)&amp;',login)[0]
port = re.findall(r'uamport=(.*)&amp;',login)[0]
macaddr = re.findall(r'mac=(.*)&amp;',login)[0]
challenge = re.findall(r'challenge=(.*)&amp;',login)[0]
print(login, nasid, ipaddr, port, macaddr, challenge)
print("Attempting to Connect")
# Put the required parameters into the login URL
loginURL = f"https://telstra.portal.fon.com/jcp/telstra?res=vnp-login&nasid={nasid}&uamip={ipaddr}&uamport={port}&mac={macaddr}&challenge={challenge}&ANID={anid}&ANIDPASSWORD={anidpassword}"
loggingIn = session.get(loginURL)
try: print("Error:", re.findall(r'<div class="error">.*\n.*<span>(.*)</span>', loggingIn.text)[0])
except IndexError: pass
if loggingIn.text.find("You&#39;re connected!") and re.findall(r'<LogoffURL>(.*)</LogoffURL>', loggingIn.text):
print("You're connected!")
print("LogoffURL:", re.findall(r'<LogoffURL>(.*)</LogoffURL>', loggingIn.text)[0])
@joshbode
Copy link

Thanks @Steve-Tec - this is great! Thank you for working out the auth flow :)

I had some trouble with HTML-encoding on the Telstra Air AP I was connecting to and changed the parsing a little - this is what is working for me:

#! /usr/bin/env python

import re
import sys
from urllib.parse import parse_qs

import requests

# This isn't your Telstra ID but rather the Fon credentials found in the Telstra Air app
# you can also find this in the network tab of inspect element when logging in normally.
anid = "m61400000000@wifi.telstra.com"
anidpassword = "..."

session = requests.Session()

# Get the Telstra Air login URL
with session.get("http://msftconnecttest.com/redirect") as response:
    text = response.text

match = re.search(r"(?<=<LoginURL>)(.*)(?=</LoginURL>)", text)
if not match:
    print("Already Connected")
    sys.exit()

login = match.group(0)

print(f"Attempting to Connect")

# Put the required parameters into the login URL
url, query = login.split("?", 1)
params = {
    **{k: v[0] for k, v in parse_qs(query).items()},
    "res": "vnp-login",
    "ANID": anid,
    "ANIDPASSWORD": anidpassword,
}

with session.get(url, params=params) as response:
    text = response.text

match = re.search(r"(?<=<LogoffURL>)(.*)(?=</LogoffURL>)", text)

if match:
    print("Connected")
    print("Logout URL:", match.group(0))
else:
    errors = re.findall(r'<div class="error">.*\n.*<span>(.*)</span>', text)
    print("Error:")
    for error in errors:
        print(error)

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