Skip to content

Instantly share code, notes, and snippets.

@koreapyj
Last active October 31, 2025 07:18
Show Gist options
  • Save koreapyj/483bb451d28a50ce8730d01574a3bef3 to your computer and use it in GitHub Desktop.
Save koreapyj/483bb451d28a50ce8730d01574a3bef3 to your computer and use it in GitHub Desktop.
#!/bin/ash
uci show firewall | grep 'Proxy-HTTP-' | while read -r line; do
uci_path="$(echo "$line" | sed -n 's/\(firewall.*\)\.name=.*/\1/p')";
domain="$(echo "$line" | sed -n "s/.*='Proxy-HTTP-\(.*\)'/\1/p")";
ipaddr="$(nslookup -type=a $domain 1.1.1.1 | sed -n 's/address: \(.*\)/\1/pi' | head -n1)";
dest_ip="$(uci get "${uci_path}.dest_ip")";
if [ -z "$uci_path" ] || [ -z "$domain" ] || [ -z "$ipaddr" ] || [ -z "$dest_ip" ]; then
>&2 echo "something went wrong. abort.";
>&2 echo "uci_path='$uci_path'";
>&2 echo "domain='$domain'";
>&2 echo "ipaddr='$ipaddr'";
>&2 echo "dest_ip='$dest_ip'";
uci revert firewall;
exit 1;
fi
if [ "$dest_ip" != "$ipaddr" ]; then
uci set "${uci_path}.dest_ip=$ipaddr"
fi
done
uci commit firewall && service firewall reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment