yashsingh1/xdaforums huggingface dataset:
[Android Apps and Games] PerfectSlayer:
Yes, this could be great! :D It should not be to hard to add it to the app but I would like to be sure the command works well for everyone before.

Is there some tester here that could try if the command works well for them? I mean, blacklist a famous site (who said google.com? :angel:) then run the command and check if the hosts file was applied without reboot. It would be better to have more feedback about if it works, if the command is available for all, if the network interface name differs, etc before start coding anything.

By the way, thanks to [MENTION=5542764]misterpyrrhuloxia[/MENTION] for the tips :good:
[Android Apps and Games] JohnnyEighty:
this could be integrated in adaway then no more reboot after update, nice find
[Android Apps and Games] DEVILOPS 007:
I'll give it a try and let you know.

---------- Post added at 11:38 AM ---------- Previous post was at 11:29 AM ----------

I'm not sure if it works on nougat. It may work on older versions but I'm getting errors when doing it [MENTION=1143630]osmosis[/MENTION] [MENTION=2822685]PerfectSlayer[/MENTION]

$ ndc resolver flushnet wlan0

No command 'ndc' found, did you mean:

Command 'dc' from package 'bc'

Command 'ncdc' from package 'ncdc'

Command 'nc' from package 'netcat'

$ su

$ ndc resolver flushnet wlan0

500 0 Resolver unknown command
[Android Apps and Games] PerfectSlayer:
If we look at the OASP source code (yep code is law :cool:), the command flushnet has been removed and nothing else seems to be available to flush: https://android.googlesource.com/pl...droid-7.1.2_r6/server/CommandListener.cpp#814

Does anyone have a better idea? I keep searching... :fingers-crossed:
[Android Apps and Games] SonOfSparda:
Hello guys, Sorry for noob questions. I've rooted my phone using Magisk v12.

*Do I have to re-apply hosts after dirty flashing ROM?

*I've already applied hosts files without enabling systemless mode in Magisk, Now how do I get systemless hosts to work?
[Android Apps and Games] flocke000:
1. No (if you use systemless mode).

2. Go to AdAway, hit "Disable Ad Blocking", enable systemless hosts in Magisk Manager, reboot, go to AdAway and re-enable Ad blocking.
[Android Apps and Games] SonOfSparda:
Thanks for reply :)

Just few more: I've seen a flashable zip for systemless hosts, what is that for? and If I got systemless mode to be working then how do I disable it?
[Android Apps and Games] 63ck0:
To disable systemless hosts, just go to Magisk Manager settings and disable systemless hosts. That's it!
[Android Apps and Games] githyanki:
Do not use that zip with magisk.
[Android Apps and Games] Rebel7022:
How do you use that zip though?
[Android Apps and Games] Pkt_Lnt:
Remove Adaway, reboot. Use another root method, flash the zip. Install version of Adaway from before dev preview in post 1. The dev preview in post 1 is set up to use systemless root, the older version does not, so the zip was included. With Magisk now, no need for the zip. Go back to the dark ages if you want. :eek: :confused:
[Android Apps and Games] Rebel7022:
So that magisk module in the magisk download section is pointless?:cyclops:
[Android Apps and Games] Pkt_Lnt:
Precisely! Exactly! Affirmative! YES!!!!!!!!!!!!!!!!!!!!!

As stated here, https://xdaforums.com/showpost.php?p=71980698&postcount=8902
[Android Apps and Games] Rebel7022:
Cool beans :victory:
[Android Apps and Games] pkelly517:
True. But this looks like it's taking a dozen steps to save one.
[Android Apps and Games] Pkt_Lnt:
And not working on Nougat that I have on both Nexus devices. :(

Looking at the time savings more than the steps, plus I have Smart Lock between phone, watch, tablet, and Chromebook, so something does not work for the time it takes whatever device to boot. :cyclops:
[Android Apps and Games] Crsmsg:
Work perfectly on Lineageos 14. THANKS
[Android Apps and Games] Beakhole:
I did see one command in there:

resolver clearnetdns [netid]

so maybe:

resolver clearnetdns wlan0

Is that the equivalent? I don't have Nougat so I can't test it.

I'm curious how it worked on LineageOS 14? Isn't that Nougat?
[Android Apps and Games] Beakhole:
Also, I just blacklisted google.com:

Then updated Adaway and cache was cleared automatically. Then I checked google.com in Chrome and got this:

Then I went back into Adaway and removed Google from the blacklist and then it cleared cache again and I went back into Chrome and went to Google again and got this:

I think it's safe to say it works perfectly in Marshmallow but we still need to figure out the right command for Nougat.

I also just realized that I failed to mention in my post that those clear DNS cache commands have to be run with root.
[Android Apps and Games] Pkt_Lnt:
OK, changing the

clearnetdns

instead of

flushnet

(all lines) works in Nougat 7.1.1 for me. I had to edit line 15 to get rid of the triangle exclamation Tasker warning, just opening and closing worked.

This is a flipping masterpiece I must say! :highfive:
[Android Apps and Games] osm0sis:
Perfect! So we'd either need to run both versions of the command or select based on OS version. Then we just need a simple way to get the active interfaces in a simple list so then they can be easily looped through. :)

Edit: This might do the trick with a filter to get rid of the nonsense interfaces! :good:

hammerhead:/ $ su
hammerhead:/ # ls /sys/class/net
lo rev_rmnet2 rev_rmnet6 rmnet1 rmnet5 wlan0
p2p0 rev_rmnet3 rev_rmnet7 rmnet2 rmnet6
rev_rmnet0 rev_rmnet4 rev_rmnet8 rmnet3 rmnet7
rev_rmnet1 rev_rmnet5 rmnet0 rmnet4 sit0
hammerhead:/ #

lo p2p0 and wlan0 would probably be the only ones that would qualify.

Edit 2:

ls /sys/class/net | grep -vE 'rmnet|sit'

Should do the trick. :D

So..

for i in $(ls /sys/class/net | grep -vE 'rmnet|sit'); do
ndc resolver flushnet $i;
ndc resolver clearnetdns $i;
done;

:highfive:
[Android Apps and Games] IronTechmonkey:
You got Tasker on my Adaway!

You got Adaway on my Tasker!

Two great tastes that go great together!

My Adaway and web usage is so simple that I only update lists when flashing ROMs (be that weekly, monthly, or yearly) however it is awesome to see this development (in multiple senses of the word) and as a Tasker user it has been educational.

Big thanks [MENTION=5542764]misterpyrrhuloxia[/MENTION] as well as, [MENTION=2822685]PerfectSlayer[/MENTION], [MENTION=4403217]Pkt_Lnt[/MENTION] [MENTION=7494055]DEVILOPS 007[/MENTION], [MENTION=4544860]osm0sis[/MENTION], [MENTION=7038087]Crsmsg[/MENTION], et al for kicking this around and testing it, and of course thanks [MENTION=3355398]mrRobinson[/MENTION] for giving us something to kick around.

Sorry for the OT but at least it was a rave rather than rant. I'll shut up now and get back to my popcorn, continuing to watch this great show.
[Android Apps and Games] Beakhole:
So let me get this straight, the command that worked in Nougat was this?

resolver flushnet wlan0

Is that right? And what about the 15th action in the Tasker Profile did you have to change by "opening and closing" it? The 15th action in the task is the notify action.

Wow! That's so perfect!!
[Android Apps and Games] osm0sis:
The ndc command doesn't seem to work for me however.. google.ca and google.com stay unblocked despite it reporting successful with clearnetdns. :confused:
[Android Apps and Games] Pkt_Lnt:
No, it needs to be

resolver clearnetdns wlan0

Changing "flushnet" to "clearnetdns" in task lines 8-13 and line 15 showed the Adaway icon and the error triangle thingie (tm) that Tasker users., after importing the profile. Just opening that line and closing it solved the error triangle, likely validated the link and/or downloaded the Adaway icon in the link. That seems to happen on import only with importing.
[Android Apps and Games] Beakhole:
So I'm in Marshmallow and clearnetdns still works. So I'm pretty sure that it doesn't actually clear the DNS cache.

root@shamu:/ # ndc resolver clearnetdns wlan0
200 0 Resolver command succeeded

I found this page that has a bunch of DNS-related commands for a bunch of past versions of Android with Lollipop being the latest version. MM seems to match LP for which commands they are.

But on that site,

clearnetdns

is on there, right below the command

setnetdns

So I get the feeling that setnetdns is for setting DNS, clearnetdns is for clearing that setting, and flushnet is for flushing the DNS cache.

But if setnetdns and clearnetdns are both still in Nougat, shouldn't some command for flushing the DNS still be present, even if Google changed the exact command?
[Android Apps and Games] osm0sis:
Doesn't look like it: https://android.googlesource.com/pl...droid-7.1.2_r6/server/CommandListener.cpp#814

Damn.
[Android Apps and Games] jcmm11:
Based on my tests that grep removes needed interfaces. I was still able to connect after running the command with the grep. Removing that and running against the full list worked.

I setup a script file and let Tasker execute that file. Also put in a sleep 2 command at the front just to ensure that Adaway finished applying hosts before I start to flush dns. Since it's in the background I figure better to play it safe and add in the short delay, although it's probably not needed.
[Android Apps and Games] Beakhole:
Are you on Nougat? If so, have you successfully cleared cache and actually got it to work?
[Android Apps and Games] jcmm11:
Yes and yes

Edit: here's my current script

#!/system/bin/sh
#
release=$(getprop ro.build.version.release|cut -b 1)
sleep 2
#
for iface in $(ls /sys/class/net)
do
if [ $release -lt 7 ]
then
ndc resolver flushnet $iface
else
ndc resolver clearnetdns $iface
fi
done
[Android Apps and Games] vikasb32:
Anyway to hide ads in peel remote app?this app consist full screen ads and adaway unable to hide it .
[Android Apps and Games] Beakhole:
Wait, so you're on Nougat and have you actually run this and tested it by blocking a host name and then testing if it's blocked without rebooting?

ndc resolver flushnet wlan0
[Android Apps and Games] jcmm11:
Yes I've run it. Yes it works for nougat. The flushnet part should work for marshmallow or lower, but I can't test that.

I just ran it again to absolutely make sure. Blocked google.com then unblocked it. Successfully in both cases.
[Android Apps and Games] Beakhole:
[Deleted]
[Android Apps and Games] Crsmsg:
[MENTION=5542764]misterpyrrhuloxia[/MENTION] yes Lineageos14 is based on Nougat 7.1.2. I thought that's your script is working but not. Strange thing i discovered that updating host on this rom no need to reboot.
[Android Apps and Games] osm0sis:
Still not working here. :confused:
[Android Apps and Games] PerfectSlayer:
Exactly. cleardns is not for flushing DNS. It should be for setting/unsetting DNS server. That's why I said I didn't find flush DNS command when I looked at the source code.

You could change the tag of the browsed source code to check which version support the command:

Android 7.1.2 : missing (https://android.googlesource.com/pl...droid-7.1.2_r6/server/CommandListener.cpp#814)

Android 6.0.1 : missing (https://android.googlesource.com/pl...roid-6.0.1_r79/server/CommandListener.cpp#831)

Android 5.1 : present (https://android.googlesource.com/pl...id-cts-5.1_r18/server/CommandListener.cpp#817)

Android 4.4 : present (https://android.googlesource.com/platform/system/netd/+/android-cts-4.4_r4/CommandListener.cpp#978)

So we need to find another way to flush DNS for Marshmallow and after :(
[Android Apps and Games] osm0sis:
Ah, so it used to be flushif before it was flushnet.. looks like we're not the only ones trying to keep track:

https://github.com/bparmentier/DNSSetter/wiki/ndc-resolver-commands

https://github.com/ukanth/afwall/wiki/DNS#resolver-commands

I haven't found a current equivalent for later Marshmallow revisions/Nougat.

[MENTION=3249429]ukanth[/MENTION] might know?
[Android Apps and Games] Beakhole:
I'm on Marshmallow, 6.0.1, and flushnet is working perfectly for me.
[Android Apps and Games] osm0sis:
Probably just depends on the branch or revision.
[Android Apps and Games] PerfectSlayer:
I'm still digging into the AOSP. I may have found something but I still can't get working (yet! That's why I'n sharing it to let find a way to get it work ;))

I found how Android flush the DNS cache when the DNS servers change:

1872 private void flushVmDnsCache() {
1873 /*
1874 * Tell the VMs to toss their DNS caches
1875 */
1876 [B]Intent intent = new Intent(Intent.ACTION_CLEAR_DNS_CACHE);[/B]
1877 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1878 /*
1879 * Connectivity events can happen before boot has completed ...
1880 */
1881 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
1882 final long ident = Binder.clearCallingIdentity();
1883 try {
1884 [B]mContext.sendBroadcastAsUser(intent, UserHandle.ALL);[/B]
1885 } finally {
1886 Binder.restoreCallingIdentity(ident);
1887 }
1888 }

Which is called by ConnectivityServices.updateDnses().

Whole source code here: https://android.googlesource.com/pl.../android/server/ConnectivityService.java#1890

So what we learned here:

There is an (internal) intent to flush DNS,

Setting DNS flush the DNS cache.

So I tried to broadcast intent with am command:

am broadcast all -a android.intent.action.CLEAR_DNS_CACHE

But it doesn't look like to work. You could try to play with it to find what I miss. I'll also look for who's in charge of applying this intent to find who's cleaning the DNS ;)

The other option is to get current DNS server and set them again. It should trigger the DNS cache flush (but we need some Java code here which means to test version of the app). Nevertheless, it could be a clever and portable (should work for all Android versions) to flush the DNS cache (if Android doesn't check the new server are the same as the old one...).

Keep posting your findings! :fingers-crossed:
[Android Apps and Games] Beakhole:
Check out this idea someone had!!

I just disabled my Tasker profile and then blacklisted google.com again, then ran that command that person suggested as a workaround:

ndc resolver setnetdns wlan0 192.168.8.1 192.168.8.1

and it worked!

Here's what I did in the terminal:

root@shamu:/ # ndc resolver setnetdns wlan0 192.168.8.1 192.168.8.1
200 0 Resolver command succeeded
root@shamu:/ # ndc resolver clearnetdns wlan0
200 0 Resolver command succeeded

So I blacklisted Google, ran those two commands, and then checked Google in Chrome and it was blocked!

Then I reverted the hosts file to default and ran those two commands again and then checked Google again and it wasn't blocked anymore!

Can you guys on Nougat try this out?
[Android Apps and Games] PerfectSlayer:
This should work for everyone as you are setting then clearing DNS server as changing DNS server should trigger DNS cache flush.

But if a user already has a custom DNS server set, you will erase his settings and leave it with default DNS server. That's why I proposed to reapply the same DNS server instead.

So, if no DNS server set, apply one then clear it. If a custom DNS server set, clear it then reapply it. What do you think about it?
[Android Apps and Games] osm0sis:
Not exactly sure what the interactions are between the props and netd, but they do list the dns nameservers for rmnet (mobile data), so maybe this will work?

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
if [ "$(getprop net.$i.dns1)" -o "$(getprop net.$i.dns2)" ]; then
dns1=$(getprop net.$i.dns1); dns2=$(getprop net.$i.dns2);
ndc resolver clearnetdns $i;
ndc resolver setnetdns $i "" $dns1 $dns2;
else
ndc resolver setnetdns $i "" 127.0.0.1 127.0.0.1;
ndc resolver clearnetdns $i;
fi;
done;

No harm in running all the variations, since it seems from people's reports that we can't totally rely on Android or SDK version to tell us which is supported.

Edit: Hmm main nameservers for wlan (wifi) and probably eth (ethernet) are under net.dns1 and net.dns2 so I guess that'll need to be added. I'm crashing to bed now though.

I also haven't tested with localhost as the dummy dns but figured it was worth a try and might be better than using an internal network 192.168.* address that could potentially exist.
[Android Apps and Games] xdarthanonx:
It seems flushDnsCache is still in the codebase for Nougat 7.1.1 but is no longer in CommandListener.cpp:

http://androidxref.com/5.1.1_r6/search?q=flushDnsCache

http://androidxref.com/6.0.1_r10/search?q=flushDnsCache

http://androidxref.com/7.1.1_r6/search?q=flushDnsCache
[Android Apps and Games] DEVILOPS 007:
Sorry I know this is unrelated to what is going on here but can I ask what those 2 blacklist addresses are for please. Not the google one, thanks:)
[Android Apps and Games] Beakhole:
The cloudfront one was an ad server that I found through tcpdump that wasn't blacklisted by any of my sources at the time (this was over a year ago). The YouTube no cookie I found through tcpdump as well but I'm unsure exactly what it does. I've just had it blacklisted for about a year and a half.
[Android Apps and Games] jcmm11:
Don't know what to say. It's definitely working here. Wonder if Google Connectivity Services (which I do have) makes a difference? Or carrier? I'm currently on Pure Nexus, 7.1.1. Should be 7.1.2 by tomorrow so I'll check if that changes things. Also carrier is Project Fi.

Is the dns cache stored in memory or is there a physical file/location associated with it?
[Android Apps and Games] surya1_:
In YouTube ad is not blocking , is there any tweak I can do and I'm using one plus 3 stock rom
[Android Apps and Games] timbohobbs:
Not through adaway but this is a very active thread

https://xdaforums.com/showthread.php?t=3560900
[Android Apps and Games] Beakhole:
You could also use YouTube Adaway if you have Xposed. That's what I use.
[Android Apps and Games] surya1_:
I'm on 7.1.1 there is no Xposed available right now
[Android Apps and Games] Beakhole:
This is a perfect idea in my opinion! Let me give it a try!
[Android Apps and Games] YourWorstFears:
Any idea why adaway doesn't block pop-up ads like spam or those ads that make your phone vibrate. Those are the most annoying ads
[Android Apps and Games] androcraze:
You haven't black-listed those sites?
[Android Apps and Games] Rebel7022:
I have googled this but it was confusing. Say I'm at a site and I click on something and a pop-up appears how do I get the info on the pop-up to adaway so adaway can block in the future?
[Android Apps and Games] Beakhole:
So I tried running this:

getprop net.$i.dns1

as this:

getprop net.wlan0.dns1

and got this:

root@shamu:/su/bin # getprop net.wlan0.dns1

root@shamu:/su/bin #

I'm not sure why. Why is it returning nothing?

EDIT: Why is it when I run this:

root@shamu:/su/bin # ndc resolver setnetdns wlan0 "" 127.0.0.1 127.0.0.1
200 0 Resolver command succeeded

It supposedly changes it. But when I run this right after, it returns nothing:

root@shamu:/su/bin # getprop net.wlan0.dns1

root@shamu:/su/bin #
[Android Apps and Games] osm0sis:
Like I said, there are no wlan or eth ones​, they just appear to use​ the main net.dns1/2 props. Type `getprop | grep net`, you'll see what I mean.
[Android Apps and Games] androcraze:
In AdAway, tap the three dots in the upper right:

. . . -> Log DNS requests -> TCP DUMP (IS NOT RUNNING/IS RUNNING)

Run the offending page or app, "Open Log File" to see what's getting through.
[Android Apps and Games] Beakhole:
[MENTION=2822685]PerfectSlayer[/MENTION],

[MENTION=4403217]Pkt_Lnt[/MENTION]

, [MENTION=7494055]DEVILOPS 007[/MENTION], and [MENTION=7038087]Crsmsg[/MENTION], have you guys been able to test [MENTION=4544860]osm0sis[/MENTION]'s script above in Nougat? I'm wondering if that's all that's needed or if it needs more work.
[Android Apps and Games] jcmm11:
Well I found out why it appeared to work for me. I don't need to reboot, changes are applied immediately.

Also I have no DNS servers in my build.prop, and no resolv.conf either.
[Android Apps and Games] Pkt_Lnt:
Uh, no bueno.
[Android Apps and Games] jcmm11:
I do however have DNS servers being set by setprop or equivalent.
[Android Apps and Games] Beakhole:
I got the same thing when I ran it on my Nexus 6 on 6.0.1. I'm thinking all those failure messages are where it tried to run on an invalid interface or something.
[Android Apps and Games] Pkt_Lnt:
Yeah, that screen shot was one third of the error run. :eek:
[Android Apps and Games] osm0sis:
Yep those failures are just it running the KitKat and Lollipop/Marshmallow versions. No big deal. I could only get it working intermittently with a www.google.ca blacklist item in my testing the other night, no idea why but it did work sometimes. :confused:

Maybe Chrome doing it's own caching?

chrome://net-internals/#dns

..but clearing that didn't seem to have any effect either; just as intermittent.

So while that test script is missing the eth/wlan workaround, beyond that we're still missing some other piece of the puzzle I feel..
[Android Apps and Games] Beakhole:
I can tell you right now that Chrome does do it's own DNS caching. I discovered that recently when I was trying to test my Tasker Profile for flushing the cache. Try using a different browser when running the test.
[Android Apps and Games] DEVILOPS 007:
Has anyone tried those commands on nougat? I'm about to test it.
[Android Apps and Games] osm0sis:
As stated, was intermittently working for me - most likely due to Chrome's extra layer of DNS caching. So.. probably works? Just needs a fix-up for wlan/eth... give me a few minutes and I'll edit it into this post. :good:

Edit: Because of the intermittent results of my earlier testing I'm also still not sure 127.0.0.1 works or not, but here's the latest:

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;
[Android Apps and Games] DEVILOPS 007:
Okay thanks, I tried it and all seemed to work fine. There wasn't any output for me but I didn't need to reboot for adaway to apply.
[Android Apps and Games] osm0sis:
That's weird. There should be output. Maybe you didn't execute it as root? In that case the for loop would be empty. Maybe you're also using one of the ROMs that automatically updates from the hosts file.
[Android Apps and Games] Beakhole:
Ok, so I switched to Data and turned off wifi and then ran:

root@shamu:/ # getprop net.rmnet_data0.dns1
198.224.164.135
root@shamu:/ # getprop net.rmnet_data0.dns2
198.224.160.135
root@shamu:/ #

Then I blacklisted Google in Adaway, ran the script again, then pinged Google and it was blocked. Then I removed Google, ran the script again, then pinged Google again and it was back to working like normal and was no longer blocked.

So this script works in MM whether on WiFi or data. And when I'm on data, it does revert the DNS back to what it was before like it's supposed to.

So I can't get this to break while on MM. Don't know about Nougat yet.

[MENTION=2822685]PerfectSlayer[/MENTION], have you given [MENTION=4544860]osm0sis[/MENTION]'s new script a try yet on Nougat?