chore: optimised the logic of dns processing

This commit is contained in:
huzibaca 2024-10-28 13:09:55 +08:00
parent a127cd6444
commit 014829e69a
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302
2 changed files with 7 additions and 10 deletions

View File

@ -49,10 +49,9 @@ hardware_port=$(networksetup -listallhardwareports | awk -v dev="$nic" '
original_dns=$(networksetup -getdnsservers "$hardware_port")
if [ ${#original_dns} -gt 15 ]; then
echo "Empty" >original_dns.txt
else
echo $original_dns >original_dns.txt
if [ ${#original_dns} -le 15 ]; then
if [ -n "$original_dns" ]; then
echo $original_dns >original_dns.txt
networksetup -setdnsservers "$hardware_port" "$1"
fi
fi
networksetup -setdnsservers "$hardware_port" "$1"

View File

@ -15,8 +15,6 @@ hardware_port=$(networksetup -listallhardwareports | awk -v dev="$nic" '
if [ -f original_dns.txt ]; then
original_dns=$(cat original_dns.txt)
else
original_dns=$(networksetup -getdnsservers "$hardware_port")
networksetup -setdnsservers "$hardware_port" $original_dns
rm -rf original_dns.txt
fi
networksetup -setdnsservers "$hardware_port" $original_dns