Last active
December 1, 2024 19:28
-
-
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
This file contains hidden or 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/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
Thank you good sir, this helped me connect to wifi on the train