Skip to content

Instantly share code, notes, and snippets.

@anjomro
Forked from hacker-bastl/bahn.sh
Last active April 4, 2024 23:05
Show Gist options
  • Save anjomro/acfa273fbf4fcd605f4c63bf86e9d234 to your computer and use it in GitHub Desktop.
Save anjomro/acfa273fbf4fcd605f4c63bf86e9d234 to your computer and use it in GitHub Desktop.
WIFIonICE Automatic Login
#!/bin/bash
set -e
PORTAL="login.wifionice.de"
# Read route components for default route. Cloudlfare ip used to detect default route
IFS=' ' read -ra IPROUTE <<< $(ip route get 1.1.1.1)
DEV=${IPROUTE[4]}
GATEWAY=${IPROUTE[2]}
# Read line containing MAC for default interface
IFS=' ' read -ra MACIF <<< $(ip address show $DEV | grep link/ether)
MAC=${MACIF[1]}
# Get ip of iceportal, assume that wifi gateway can act as dns server
PORTALIP=$(dig +short $PORTAL @$GATEWAY)
echo -e "dev: $DEV\ndns: $GATEWAY\nmac: $MAC\nportalip: $PORTALIP"
COOKIEJAR="wifionice-cookies.txt"
# get the CSRF token required for login
curl -vs -o /dev/null -c $COOKIEJAR --resolve $PORTAL:80:$PORTALIP "http://$PORTAL/de/"
IFS=$'\t' read -ra ALLCOOKIES <<< $(cat $COOKIEJAR | grep csrf)
TOKEN=${ALLCOOKIES[6]}
echo "CSRF: $TOKEN"
# perform WIFIonICE login
curl -vvv --resolve $PORTAL:80:$PORTALIP -b $COOKIEJAR -H "Content-Type: application/x-www-form-urlencoded" -H "Connection: keep-alive" --data "login=true&CSRFToken=$TOKEN&connect=" "http://$PORTAL/de/?mac=$MAC"
rm $COOKIEJAR

WIFIonICE Automatic Login

This connector intends to automate the process of logging in into the public wifi inside of an IC /ICE of the German railways. The adapter enables does enable you to choose and keep a custom DNS server.

Usage on Linux

The script should be usable on most Linux systems, at least if the following requirements are met:

  • bash
  • ip
  • dig

Usage on Android

The script can speed up the process of logging into the ice wifi greatly. To get the script working under Android follow these steps:

  • Install the terminal emulator Termux
  • Install the Termux Widget Extension
  • Install dependencies: Open Termux and run command: pkgs install -y dnsutils wget
  • Download the script in the ~/.shortcuts/ folder
    • How to download the script in the folder
      • Open Termux and enter the following commands:

        cd ~/.shortcuts

        wget https://gist.github.com/anjomro/acfa273fbf4fcd605f4c63bf86e9d234/raw/6455886ac3e993f4cd3ba9313865d73375905083/wifionice-autoconnect.sh

  • Create Home Screen Widget, select script (You may need to give additional permissions for termux (Settings/Apps/Termux/Permissions/Display over other apps)
  • To run script and login into ICE wifi just click the icon on the homescreen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment