Skip to content

Instantly share code, notes, and snippets.

@bzamecnik
Last active July 9, 2023 17:30
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bzamecnik/46bd84c530e61a706ddca8a19263e2c1 to your computer and use it in GitHub Desktop.
Save bzamecnik/46bd84c530e61a706ddca8a19263e2c1 to your computer and use it in GitHub Desktop.
Accept ČD Wifi on the command line (if you hate clicking). http://cdwifi.cz
#!/bin/bash
# Accept CD Wifi (Czech railways) on the command line (if you hate clicking).
# http://cdwifi.cz
#
# Put the script to ~/bin/cdwifi and make sure that export it's on the path: PATH=$PATH:~/bin
# Note that if you have a custom DNS set (eg. 8.8.8.8 or 1.1.1.1) they don't resolve
# cdwifi.cz. If you don't want to use their DNS set via DHCP for all your traffic
# the workaround here is to query their DNS server at the gateway just
# for this request.
#
# It works on Mac and should also work on Linux.
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
GATEWAY=$(route -n |grep '^0.0.0.0' |sed 's/ \+/ /'|cut -d' ' -f 2)
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
GATEWAY=$(route get default|grep gateway:|sed 's/.*: //')
fi
if [ ! -z "$GATEWAY" ]; then
HOST=$(nslookup cdwifi.cz $GATEWAY|grep 'Address: '|sed 's/.*: //')
else
echo "Warning: can't lookup IP address of cdwifi.cz"
HOST=cdwifi.cz
fi
curl -s \
-o /dev/null \
-w "%{http_code}\n" \
-b 'user.email=eula@accepted' \
-H 'Host: cdwifi.cz' \
http://${HOST}/portal/api/vehicle/gateway/user/authenticate?url=http://cdwifi.cz/ \
| grep -q 307 \
&& echo OK \
|| echo Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment