2024-09-02 12:35:33 -05:00
|
|
|
#!/bin/env bash
|
|
|
|
|
|
|
|
# This script allows one to log into captive portals by temporarily using the provided DNS records. Otherwise, captive portals
|
|
|
|
# don't work with custom resolvconf setups
|
|
|
|
|
2024-12-06 22:57:38 -06:00
|
|
|
set -e
|
|
|
|
|
2024-09-02 12:35:33 -05:00
|
|
|
# Get the DNS resolver provided by the network
|
2024-09-04 09:30:34 -05:00
|
|
|
DNS=$(nmcli -f IP4.DNS dev show wlan0 | awk '{print $2}' | head -1)
|
2024-09-02 12:35:33 -05:00
|
|
|
|
|
|
|
# Temporarily put the DNS resolver in place
|
2024-09-02 12:37:43 -05:00
|
|
|
echo "Need sudo permission to work with /etc/resolv.conf"
|
2024-09-02 12:35:33 -05:00
|
|
|
sudo cp /etc/resolv.conf /etc/resolv.conf.bk
|
|
|
|
echo "# Temporary resolv.conf generated by captive-portal-login.sh" | sudo tee /etc/resolv.conf
|
|
|
|
echo "nameserver $DNS" | sudo tee -a /etc/resolv.conf
|
|
|
|
|
2024-12-06 22:57:38 -06:00
|
|
|
echo "Put temporary DNS resolver in place. Fix the captive portal before continuing."
|
|
|
|
xdg-open 1.1.1.1
|
2024-09-02 12:35:33 -05:00
|
|
|
|
|
|
|
read -p "Press enter to continue..."
|
|
|
|
|
|
|
|
# Put back own resolvers
|
|
|
|
sudo mv /etc/resolv.conf.bk /etc/resolv.conf
|
|
|
|
|