Skip to content

Instantly share code, notes, and snippets.

@mid-kid
Last active November 15, 2023 20:21
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 mid-kid/b60563059a393f90522f5e57aabfc493 to your computer and use it in GitHub Desktop.
Save mid-kid/b60563059a393f90522f5e57aabfc493 to your computer and use it in GitHub Desktop.
WiFi in de trein auto login script
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment