Created
January 7, 2018 20:13
-
-
Save DosAmp/7dfac4c947c6cf6d90c4e4c5ced33696 to your computer and use it in GitHub Desktop.
Automatic login to Deutsche Bahn Wi-Fi
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
#!/usr/bin/env python3 | |
import re | |
import requests | |
LOGIN_URL = "http://www.wifionice.de/de/" | |
CSRF_REGEX = re.compile(b'"CSRFToken" value="([0-9a-f]+)"') | |
print("Einloggen...") | |
with requests.Session() as s: | |
resp = s.get(LOGIN_URL) | |
for line in resp.iter_lines(): | |
match = CSRF_REGEX.search(line) | |
if match: | |
token = match.group(1).decode(resp.encoding) | |
login_data = {"login": "true", "CSRFToken": token, "connect": ""} | |
resp = s.post(LOGIN_URL, data=login_data) | |
for line in resp.iter_lines(): | |
if b'class="user-online' in line: | |
print("Login erfolgreich!") | |
break |
I have not used this script in a long time, but I'm currently riding an ICE train and found following small differences:
- The login URL is now
https://login.wifionice.de/de/
. Scraping the CSRF token should still work the same way. - POST data now only consists of the
login
andCSRFToken
parameters. - Either send the request with
allow_redirects=False
and check whether theLocation
header points tohttps://iceportal.de
, or do another GET request and search for "Sie sind online".
The script should also work for DB station Wi-Fi (WIFI@DB) and DB Systel (dbs4public) hotspots, but the hostnames may vary.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just trying to adopt this on a Raspberry Pico W with Micropython but it does not work. Did somebody try this?