Revert "chore: update resource"

This reverts commit e3c52781f3.
This commit is contained in:
huzibaca
2024-10-27 05:10:26 +08:00
parent 5ef9220175
commit df3c296850
4 changed files with 3 additions and 12 deletions

58
scripts/set_dns.sh Normal file
View File

@@ -0,0 +1,58 @@
#!/bin/bash
function is_valid_ip() {
local ip=$1
local IFS='.'
local -a octets
if [[ ! $ip =~ ^([0-9]+\.){3}[0-9]+$ ]]; then
return 1
fi
read -r -a octets <<<"$ip"
if [ "${#octets[@]}" -ne 4 ]; then
return 1
fi
for octet in "${octets[@]}"; do
if ! [[ "$octet" =~ ^[0-9]+$ ]] || ((octet < 0 || octet > 255)); then
return 1
fi
done
return 0
}
if [ $# -lt 1 ]; then
echo "Usage: $0 <hardware_port>"
exit 1
fi
if ! is_valid_ip "$1"; then
echo "$1 is not a valid IP address."
exit 1
fi
nic=$(route -n get default | grep "interface" | awk '{print $2}')
hardware_port=$(networksetup -listallhardwareports | awk -v dev="$nic" '
/Hardware Port:/{
port=$0; gsub("Hardware Port: ", "", port)
}
/Device: /{
if ($2 == dev) {
print port;
exit
}
}
')
original_dns=$(networksetup -getdnsservers "$hardware_port")
if [ ${#original_dns} -gt 15 ]; then
echo "Empty" >original_dns.txt
else
echo $original_dns >original_dns.txt
fi
networksetup -setdnsservers "$hardware_port" "$1"