#!/bin/sh
# undns.sh - Restore DNS settings only (keep IP)
NX_HOME=/Library/nxproxy
NETWORKSETUP=/usr/sbin/networksetup

# If local DNS is in use (xhcp.tmp exists), quit
if [ -f "$NX_HOME/xhcp.tmp" ]; then
    echo "[undns] Local DNS in use, skipping."
    exit 0
fi

# Get all active network services
INTERFACES=$($NETWORKSETUP -listallnetworkservices | grep -v "^\*" | tail -n +2)
while IFS= read -r iface; do
    echo "[undns] Clearing DNS: $iface"
    $NETWORKSETUP -setdnsservers "$iface" empty
done <<< "$INTERFACES"

echo "[undns] Done."