Skip to content

Instantly share code, notes, and snippets.

@jonathanhle
Last active May 12, 2023 03:10
Show Gist options
  • Save jonathanhle/9a6966d0a6296bf071ff8ba7c74c71d6 to your computer and use it in GitHub Desktop.
Save jonathanhle/9a6966d0a6296bf071ff8ba7c74c71d6 to your computer and use it in GitHub Desktop.
umbrella_dns_changer for osx
#!/bin/bash
# -----------------------------------------------------------
# Get installed OSX Network Devices and then list the ones with Active Internet Connections
# -----------------------------------------------------------
InstalledHardware=$(networksetup -listallhardwareports | grep Device | awk '{print $2}')
ActiveInterfaces=$(ifconfig | pcregrep -M -o '^[^\t:]+(?=:([^\n]|\n\t)*status: active)')
# -----------------------------------------------------------
# Get list of active network devices
# -----------------------------------------------------------
common_live_network_devices=$(for installedDevice in ${InstalledHardware}
do
for activeDevice in ${ActiveInterfaces}
do
if [ "${installedDevice}" = "${activeDevice}" ]
then
echo "${activeDevice}"
fi
done
done)
# -----------------------------------------------------------
# Find the common device names and set the setdnsservers to Umbrella
# Common like "Wi-Fi" and "Thunderbolt Ethernet Slot 1"
# -----------------------------------------------------------
for common_device in ${common_live_network_devices}
do
internet_device=$(networksetup -listallhardwareports | grep -B 1 ${common_device} | grep "Hardware Port" | cut -c 16-)
hello=$(echo networksetup -setdnsservers \"${internet_device}\" 208.67.222.222 208.67.220.220)
eval $hello
done
@jonathanhle
Copy link
Author

used https://apple.stackexchange.com/questions/402913/convert-bash-script-to-a-compiled-standalone-binary-executable-not-text to make a binary like following:

shc -f umbrella_dns_primary_device.sh
mv umbrella_dns_primary_device.sh.x umbrella_dns_primary_device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment