I just automated away something that annoyed me:
Whenever I'm in some foreign WIFI (e.g. in the train) I need to find the right URL to open in the browser to confirm some dialog or login before having access to the internet.
I recently found out that I can just enter the IP-address of the primary DNS server from my network information into the browser as the most reliable way.
But that's still to many clicks for doing it multiple times a day (e.g. when switching between trains), so I composed a few bash commands to do that for me:
xdg-open "http://$(grep "nameserver" /etc/resolv.conf | tr -d "nammeserver ")" > /dev/null &
Let's see what's happening here from inside out:
$ grep "nameserver" /etc/resolv.conf
nameserver 192.168.8.1
delivers the current primary DNS,
... | tr -d "nameserver "
drops the first word and space from the previos command so that only the IP address is left,
"http://$(...)"
prefixes the output from above commands (executed in a sub-shell) to make it a URL
xdg-open "..." > /dev/null &
opens the default browser (because the string is a URL),
-
> /dev/null
: without writing some message like "Opening in existing browser session." to the terminal -
&
: in the background (without blocking the shell)
I added the whole thing to a new wifi
alias in my ~/.extend.bashrc
:
alias wifi='xdg-open "http://$(grep "nameserver" /etc/resolv.conf | tr -d "nammeserver ")" > /dev/null &'
so it's always on my fingertips :)
PS: It's not working everywhere (e.g. not in the German ICE trains, thanks Deutsche Bahn)
and the next hit of Ctrl+C
adds the output
[n] Done ...the command...
So I'm very open for suggestion of how to improve it.
Top comments (0)