diff --git a/system/arm/bin/update-static-dns b/system/arm/bin/update-static-dns index c663486..0e0df17 100755 --- a/system/arm/bin/update-static-dns +++ b/system/arm/bin/update-static-dns @@ -5,6 +5,7 @@ export PATH=/system/bin echo "127.0.0.1 localhost $(busybox hostname)" > /system/etc/hosts echo "::1 ip6-localhost" >> /system/etc/hosts +# IPv4 for host in $(busybox cat /system/etc/static-dns-hosts.txt | busybox grep -vE '^\s*#'); do ip_addr=$(busybox nslookup -type=a "$host" 8.8.8.8 | busybox awk '/^Address: / { print $2 ; exit }') @@ -15,3 +16,20 @@ for host in $(busybox cat /system/etc/static-dns-hosts.txt | busybox grep -vE '^ echo "$ip_addr $host" | busybox tee -a /system/etc/hosts done + +# Check whether IPv6 is available. +busybox wget http://[2606:4700:4700::1111] >/dev/null 2>&1 +if [[ $? != 0 ]]; then + exit +fi +# IPv6 +for host in $(busybox cat /system/etc/static-dns-hosts.txt | busybox grep -vE '^\s*#'); do + ip_addr=$(busybox nslookup -type=aaaa "$host" 2001:4860:4860::8888 | busybox awk '/^Address: / { print $2 ; exit }') + + if [ -z "$ip_addr" ]; then + echo "Can't resolve '$host'." >&2 + continue + fi + + echo "$ip_addr $host" | busybox tee -a /system/etc/hosts +done diff --git a/system/x86/bin/update-static-dns b/system/x86/bin/update-static-dns index c663486..0e0df17 100755 --- a/system/x86/bin/update-static-dns +++ b/system/x86/bin/update-static-dns @@ -5,6 +5,7 @@ export PATH=/system/bin echo "127.0.0.1 localhost $(busybox hostname)" > /system/etc/hosts echo "::1 ip6-localhost" >> /system/etc/hosts +# IPv4 for host in $(busybox cat /system/etc/static-dns-hosts.txt | busybox grep -vE '^\s*#'); do ip_addr=$(busybox nslookup -type=a "$host" 8.8.8.8 | busybox awk '/^Address: / { print $2 ; exit }') @@ -15,3 +16,20 @@ for host in $(busybox cat /system/etc/static-dns-hosts.txt | busybox grep -vE '^ echo "$ip_addr $host" | busybox tee -a /system/etc/hosts done + +# Check whether IPv6 is available. +busybox wget http://[2606:4700:4700::1111] >/dev/null 2>&1 +if [[ $? != 0 ]]; then + exit +fi +# IPv6 +for host in $(busybox cat /system/etc/static-dns-hosts.txt | busybox grep -vE '^\s*#'); do + ip_addr=$(busybox nslookup -type=aaaa "$host" 2001:4860:4860::8888 | busybox awk '/^Address: / { print $2 ; exit }') + + if [ -z "$ip_addr" ]; then + echo "Can't resolve '$host'." >&2 + continue + fi + + echo "$ip_addr $host" | busybox tee -a /system/etc/hosts +done