Last active
October 30, 2024 14:44
-
-
Save mid-kid/b60563059a393f90522f5e57aabfc493 to your computer and use it in GitHub Desktop.
WiFi in de trein auto login script
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
#!/bin/sh | |
# Logs in automatically to the "WiFi in de trein" public hotspots, located in | |
# trains in the Netherlands. | |
# Requires: curl, sed | |
set -e | |
tmp="$(mktemp -d -p '' 'hslogin.XXXXXXXXXX')" | |
trap "rm -r '$tmp'" EXIT | |
curl="curl --dns-servers 8.8.8.8,8.8.4.4 -s -v -m 30" | |
$curl -c "$tmp/cookies" 'http://portal.nstrein.ns.nl/' > "$tmp/page" | |
token="$(sed -n -e 's/.* id="csrfToken" value="\([^"]*\)" .*/\1/p' "$tmp/page")" | |
test -n "$token" | |
$curl -b "$tmp/cookies" -X POST -H 'Content-Length: 0' -H 'Origin: http://portal.nstrein.ns.nl' -H 'Referer: http://portal.nstrein.ns.nl/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: close' "http://portal.nstrein.ns.nl/nstrein:main/internet?csrfToken=$token" > /dev/null |
yes, this worked, it even worked when i forgot to remove the dns servers listed, script works way better than all the "solutions" i found
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know if curl on ubuntu is built with adns support, I use gentoo and I had to enable it. The only reason it's there is because dnsmasq wouldn't consistently resolve domain names before logging into the portal. You can remove the
--dns-servers 8.8.8.8,8.8.4.4
option and depending on your system it might "just work".