Skip to content

Instantly share code, notes, and snippets.

@mid-kid
Last active April 15, 2025 08:08
Show Gist options
  • Select an option

  • Save mid-kid/b60563059a393f90522f5e57aabfc493 to your computer and use it in GitHub Desktop.

Select an option

Save mid-kid/b60563059a393f90522f5e57aabfc493 to your computer and use it in GitHub Desktop.

Revisions

  1. mid-kid revised this gist Nov 15, 2023. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions hslogin-nstrein
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,9 @@ set -e
    tmp="$(mktemp -d -p '' 'hslogin.XXXXXXXXXX')"
    trap "rm -r '$tmp'" EXIT

    curl -s -v -m 30 -c "$tmp/cookies" 'http://portal.nstrein.ns.nl/' > "$tmp/page"
    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 -s -v -m 30 -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
    $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
  2. mid-kid created this gist Oct 10, 2021.
    12 changes: 12 additions & 0 deletions hslogin-nstrein
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #!/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 -s -v -m 30 -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 -s -v -m 30 -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