[Android Apps and Games] Beakhole:
root@shamu:/su/bin # sh -v flush-cache
for i in $(ls /sys/class/net); do
# ndc resolver flushif $i; # KitKat and below
# ndc resolver flushnet $i; # Lollipop and Marshmallow
# Nougat and above
case $i in
wlan*|eth*) unset pre;;
*) pre=".$i";;
esac;
if [ "$(getprop net$pre.dns1)" -o "$(getprop net$pre.dns2)" -o "$(getprop net$pre.dns3)" -o "$(getprop net$pre.dns4)" ]; then
dns1=$(getprop net$pre.dns1); dns2=$(getprop net$pre.dns2); dns3=$(getprop net$pre.dns3); dns4=$(getprop net$pre.dns4);
ndc resolver clearnetdns $i;
ndc resolver setnetdns $i "" $dns1 $dns2 $dns3 $dns4;
else
ndc resolver setnetdns $i "" 127.0.0.1 127.0.0.1;
ndc resolver clearnetdns $i;
fi;
done;
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
200 0 Resolver command succeeded
root@shamu:/su/bin #

I'm not sure if I'm actually testing this properly. I commented out the KK and LP/MM commands just so I could use just the setnet clearnet commands only. No errors there. Now I'm actually going to blacklist Google in Adaway and then run this script again and see if it actually works.

---------- Post added at 10:18 AM ---------- Previous post was at 09:39 AM ----------

Ok, I blacklisted Google and then ran the latest script where I had commented out the KK, LP, and MM commands.

Then I pinged Google and got this:

root@shamu:/ # ping google.com
PING google.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.393 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.944 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.194 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.688 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.640 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.392 ms
64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.436 ms
64 bytes from localhost (127.0.0.1): icmp_seq=8 ttl=64 time=0.485 ms
64 bytes from localhost (127.0.0.1): icmp_seq=9 ttl=64 time=0.448 ms

It's pinging localhost which tells us that it successfully flushed cache with that script. I also visited Google in Chrome and it couldn't connect.

Then I removed Google from Adaway and ran the script again and the pinged Google again:

root@shamu:/ # ping google.com
PING google.com (208.187.128.23) 56(84) bytes of data.
64 bytes from 208.187.128.23: icmp_seq=1 ttl=56 time=3.29 ms
64 bytes from 208.187.128.23: icmp_seq=2 ttl=56 time=12.0 ms
64 bytes from 208.187.128.23: icmp_seq=3 ttl=56 time=3.35 ms
64 bytes from 208.187.128.23: icmp_seq=4 ttl=56 time=8.30 ms
64 bytes from 208.187.128.23: icmp_seq=5 ttl=56 time=9.08 ms
64 bytes from 208.187.128.23: icmp_seq=6 ttl=56 time=8.76 ms
64 bytes from 208.187.128.23: icmp_seq=7 ttl=56 time=8.84 ms
64 bytes from 208.187.128.23: icmp_seq=8 ttl=56 time=8.37 ms
64 bytes from 208.187.128.23: icmp_seq=9 ttl=56 time=8.95 ms
64 bytes from 208.187.128.23: icmp_seq=10 ttl=56 time=10.9 ms

And Google is back to working normally!

Btw, [MENTION=4544860]osm0sis[/MENTION] to clear the DNS cache in chrome, all you have to do is go into Chrome's clear browsing data and just clear browser cache like normal and then close chrome and then the next time you open it, the DNS cache is cleared. I just tested that.

So on Marshmallow I can at least say that, even without the flushnet command, this script works perfectly.

How many other people can test this on Nougat instead? I'm really curious if this script would work perfectly for someone on Nougat that already has custom DNS set.

Can someone with that setup give that a try? Pinging Google is the easiest way to test it.