[Solution] Blocking all Youtube Video Advertisements

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Mon Jan 13, 2020 4:40    Post subject: Reply with quote
@SurprisedItWorks
a simplified version of your script will be great idea, and please, only for youtube without using other ad's host list
Sponsor
MrPickles
DD-WRT User


Joined: 14 Jan 2017
Posts: 50

PostPosted: Mon Jan 13, 2020 10:22    Post subject: Reply with quote
I've tried all three. Rickz did mention his was for Android.

No success with any for YouTube ads via Roku or AppleTV.

MP
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Mon Jan 13, 2020 14:05    Post subject: Reply with quote
@MrPickles
blocking IP list was working for me but router got bricked somehow, wireless was not working at all Sad maybe due reasons i explained, for Vizio TV with cromecast was ok and only saw some initial 10 seconds ads by youtube, can't add all ip ranges needed due to lack of this router resources, had to recover backup of all config and it's working without any script or firewall rules
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Tue Jan 14, 2020 8:02    Post subject: Reply with quote
here's another interesting discussion about youtube ads, worth checking out.

discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/435
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Sun Jan 19, 2020 19:06    Post subject: Reply with quote
@SurprisedItWorks @mkaand @MrPickles


we just can't black list the *.googlevideo.com host/ip because it's shared between other videos, this is demonstrated and commented in some other forums, so i came to the conclusion to redirect youtube video host's to other that didn't give any ads while playing, this time i used netstat to find all host used while playing a video. found like 5 or 4 *.1e100.net used, some in standby and other with connection established, tested each ip associated with those host and got the one that didn't display any ADS

you have to find out which of the cache servers don't display ads and redirect all other host like i have it in dnsmasq options

to find ip redirector 1e100.net ranges use: hxxps://www.robtex.com/cidr/172.217.19.46-24
there are many.. not only .19 range, you could test with other ranges like 172.217.21.xx etc etc

my static DNS are:
see screen shot

in the advanced routing options, just in case, i blocked google's public dns:
Quote:
8.8.8.8 and 8.8.4.4


i have seem some videos longer than 20 minutes and the video is not interrupted with ADS in the middle or end, the worst ADS are those has 3 or 4 minutes of video duration, haven't seen any for days

in Services/dnsmasq Options i have:

Quote:
address=/1e100.net/0.0.0.70
ptr-record=70.0.0.0.in-addr.arpa,"1e100.net"

address=/DD-WRT.local/192.168.1.1
ptr-record=1.1.168.192.in-addr.arpa,"DD-WRT.local"
address=/cache.google.com/172.217.19.206
ptr-record=206.19.217.172.in-addr.arpa,"cache.google.com"

address=/pagead.l.google.com/0.0.2.0
address=/gstaticadssl.l.google.com/0.0.1.1
address=/cloudfront.net/0.0.1.2
address=/clients1.google.com/0.0.0.9
address=/manifest.googlevideo.com/172.217.19.46
ptr-record=46.19.217.172.in-addr.arpa,"manifest.googlevideo.com"

address=/criteo.com/0.0.0.8
address=/ads.facebook.com/0.0.0.7
address=/adsense.com/0.0.0.6
address=/doubleclick.net/0.0.0.5
address=/googlesyndication.com/0.0.0.4
address=/googleadsserving.cn/0.0.0.3
address=/metric.gstatic.com/0.0.0.2
address=/www.googletagservices.com/0.0.0.30
address=/googleadservices.com/0.0.0.20
address=/r1---sn-ugpjvh-nq9s.googlevideo.com/172.217.19.46
address=/r2---sn-ugpjvh-nq9s.googlevideo.com/172.217.19.46
address=/r3---sn-ugpjvh-nq9s.googlevideo.com/172.217.19.46
address=/r4---sn-ugpjvh-nq9s.googlevideo.com/172.217.19.46
address=/r5---sn-ugpjvh-nq9s.googlevideo.com/172.217.19.46
address=/r6---sn-ugpjvh-nq9s.googlevideo.com/172.217.19.46
address=/r1---sn-ugpjvh-nups.googlevideo.com/172.217.19.46
address=/r4---sn-ugpjvh-nups.googlevideo.com/172.217.19.46
address=/r5---sn-ugpjvh-nups.googlevideo.com/172.217.19.46
address=/r6---sn-ugpjvh-nups.googlevideo.com/172.217.19.46
address=/r3---sn-ugpjvh-nups.googlevideo.com/172.217.19.46
address=/r2---sn-ugpjvh-nups.googlevideo.com/172.217.19.46
address=/r3---sn-ugpjvh-nq9l.googlevideo.com/172.217.19.46
address=/r1---sn-ugpjvh-nq9l.googlevideo.com/172.217.19.46
address=/r2---sn-ugpjvh-nq9l.googlevideo.com/172.217.19.46
address=/r4---sn-ugpjvh-nq9l.googlevideo.com/172.217.19.46
address=/r5---sn-ugpjvh-nq9l.googlevideo.com/172.217.19.46
address=/r6---sn-ugpjvh-nq9l.googlevideo.com/172.217.19.46
address=/r3---sn-ugpjvh-nupl.googlevideo.com/172.217.19.46
address=/r2---sn-ugpjvh-nupl.googlevideo.com/172.217.19.46
address=/r1---sn-ugpjvh-nupl.googlevideo.com/172.217.19.46
address=/r4---sn-ugpjvh-nupl.googlevideo.com/172.217.19.46
address=/r5---sn-ugpjvh-nupl.googlevideo.com/172.217.19.46
address=/r6---sn-ugpjvh-nupl.googlevideo.com/172.217.19.46

address=/bc.googleusercontent.com/0.0.0.60
address=/r1---sn-ugpjvh-nupz.googlevideo.com/172.217.19.46
address=/r2---sn-ugpjvh-nupz.googlevideo.com/172.217.19.46
address=/r1---sn-ugpjvh-ixme.googlevideo.com/172.217.19.46
address=/r2---sn-ugpjvh-ixme.googlevideo.com/172.217.19.46
address=/r1---sn-ugpjvh-ixml.googlevideo.com/172.217.19.46
address=/r2---sn-ugpjvh-ixml.googlevideo.com/172.217.19.46



Also from this site/info: hxxps://unix.stackexchange.com/questions/47601/how-can-i-block-a-specific-url-on-a-dd-wrt-router i got the idea to block some youtube path by keyword..maybe useless and maybe some don't work, just in case i leave them there by now..
keywords:

Quote:
/ads?
/generate_204?
/adview?
/aclk?
/qoe?
www.youtube.com/mac_204?action_fcts=1
www.youtube.com/api/stats/qoe?
www.youtube.com/api/stats/ads?
www.youtube.com/generate_204?
www.google.com/pagead/lvz?
www.google.com.do/pagead/lvz?
www.youtube.com/ptracking?
www.youtube.com/pagead/paralleladview?
www.youtube.com/csi_204?
www.youtube.com/get_midroll
www.youtube.com/pagead/conversion/?


if someone want to test don't forget to reboot router after those changes and clear your browser and dns cache from windows or other devices


Last edited by Rickz on Sun Jan 26, 2020 7:35; edited 14 times in total
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Sun Jan 19, 2020 19:12    Post subject: Reply with quote
dnsmasq options i use
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Sat Jan 25, 2020 13:49    Post subject: Reply with quote
@SurprisedItWorks @mkaand @MrPickles

i believe google already black listed the redirector i used in my previous post, so everyone has to find one of those cache redirector sites that won't give the ADS Alarm and will redirect to one of the *.googlevideo.com url host without AD intervention

i'm writing about one of those 1e100.net host, not all needs to be blocked, you need to test which of those don't display ADS while using youtube, use it and test, redirect manifest and/or the googlevideo url's found in the html source code for your ISP
Quote:
(r1---sn-xxxxxx-nq9s.googlevideo.com
r2---sn-xxxxxx-nq9s.googlevideo.com
r1---sn-xxxxxx-nq9l.googlevideo.com
etc etc where xxxxxx will be different for each ISP) i supplied the ones i got but for other ISP i believe are different so by now you could redirect only manifest.googlevideo.com and block the rest of 1e100.net host, the other configs are needed to block rest of google's/youtube video ads and banners
only the statics *.googlevideo.com url found in the html source code i redirect them, no need to redirect any other as i did before so i removed them from previous post, also is not needed to block any googlevideo.com ip's

for each ISP/region location google use different host so i explained the best possible as generic way so everyone could handle this, so far so good, android + windows without ads, the trick is to find the good boy redirector as explained. this should work with any smart tv including apple devices

good luck! Laughing
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Mon Jan 27, 2020 19:52    Post subject: Reply with quote
I've been away for awhile, but way back when, I did promise a minimalist version of the adblocker I posted earlier. This youtube-only adblocker is derived from my latest, full-featured version (which you haven't yet seen but soon will). I've stripped out other block lists, diagnostics, most logging, blacklist, whitelist, and the timing feature that ensures that the network is up before beginning. Also, while this is still code for Startup, it now packages the main action as a shell script you can call from cron or wherever. The last line here calls it from Startup (with some delay first to make sure the network is up), but you can omit it if you'd rather just start it up later. I creates a /tmp/badhosts list of about 7,000 lines, and the downloads are logged in /tmp/badhosts.log.
Code:
#Youtube adblocker.  Requires dnsmasq Add'l Config lines
#"addn-hosts=/tmp/badhosts" and "address=/1e100.net/0.0.0.0"
cat <<'EOF' >/tmp/root/adblocker
#!/bin/sh
cd /tmp
D=manifest.googlevideo.com
DD=$(echo $D | sed 's/\./\\./g')
{ curl -kf https://gist.githubusercontent.com/seanhandley/d76c51099a32287c0a9074d5f15ac7d0/raw/2bde83a93e68208585d602df787d782036271438/gistfile1.txt
  curl -kf https://api.hackertarget.com/hostsearch/?q=googlevideo.com | awk -F , '{print "0.0.0.0",$1}'
  curl -kf https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt | sed '/---/d;s/^/0.0.0.0 &/'
} 2>badhosts.log | sed "s/\t/ /g; /^0\.0\.0\.0 /!d; s/ *\#.*$//; s/\r//; / $DD$/d" | sort -u > badhosts
killall -HUP dnsmasq; sleep 5
A='^Address [0-9]+: '; I='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
nslookup $D 2>/dev/null | sed -nE "/$A$I/{s/$A($I).*/\1 $D/p;q}" >>badhosts
killall -HUP dnsmasq
EOF
chmod +x /tmp/root/adblocker
( sleep 90; /tmp/root/adblocker ) &

[Edit Wed Jan 29 18:27 UTC 2020: Added an internal dnsmasq restart so that a previous badhosts won't corrupt the new nslookup value for manifest.google.com. Other minor tweaks also.]
This code is a stripped-down version of what I've been running successfully for a couple of weeks now, but in stripped-down form it has been tested only modestly. Take a look at the last line of badhosts (perhaps using tail /tmp/badhosts) to check the key manifest.googlevideo.com line. On some earlier dd-wrt builds (even as recently as early 2019), /tmp/root/adblocker will not run the file as a shell script as it should. In that case, do sh /tmp/root/adblocker instead.

_________________
2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.


Last edited by SurprisedItWorks on Wed Jan 29, 2020 18:31; edited 1 time in total
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Mon Jan 27, 2020 20:54    Post subject: Reply with quote
Here is the new, improved version of my adblocker. The reason to use it, even if you want only youtube blocking, is to get the logging and diagnostics and safety features. If you don't like it downloading other block lists, just delete the Download URL lines for the lists you don't want to use! Don't want a blacklist? Delete its entries. I've split the whitelist here into two lists, the WHITE list and the ALLWHITE list. Putting foo.com in the WHITE lists just whitelists foo.com. Putting it in the ALLWHITE list whitelists both foo.com and *.foo.com. Using two lists simplified practical whitelisting. Don't like the whitelists? Delete all entries from those lists. It's fine for all these lists to be empty.

There is a new separate PTRLIST here of sites that need special treatment like we've been giving manifest.google.com. These are ad-related sites that in the public DNS system have reverse lookups that don't point back to the original domain but instead point to weird-looking domain names seem to be somehow useful in their ad systems. Don't want those two other sites in that list? Delete them. However, to block youtube ads, you must keep manifest.google.com in that list.
Code:
#Adblocker.  Requires dnsmasq Add'l Config lines
#"addn-hosts=/tmp/badhosts" and "address=/1e100.net/0.0.0.0"
#Re manifest.googlevideo.com for youtube ad blocker, see
#https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1187268 and
#https://www.reddit.com/r/pihole/comments/9w5swx/i_think_ive_managed_to_block_youtube_ads_with/
( STARTED=/tmp/root/StartedAdBlocker
  [[ -f $STARTED ]] && exit || touch $STARTED
  ( cd /tmp; touch badhosts;
    sleep 30; until ping -c 1 -w 1 &>/dev/null cloudflare.com; do sleep 30; done; sleep 60
    cat <<'ENDPTR' >badhosts.ptr
manifest.googlevideo.com
media.trafficjunky.net
static.trafficjunky.net
ENDPTR
    sed 's/\./\\./g;s/.*/\/ &$\/d/' <<'ENDWHITE' - badhosts.ptr >badhosts.whitelist
ipleak.net
secret.[^g]+oogle.com
ny(mag|post).com
ENDWHITE
    sed 's/\./\\./g;s/.*/\/( |\\.)&$\/d/' <<'ENDALLWHITE' >>badhosts.whitelist
hulu(ad)?.com
ENDALLWHITE
    awk '{print "0.0.0.0 "$1}' <<'ENDBLACK' >badhosts.blacklist
ads.facebook.com
connect.facebook.net
ENDBLACK
    { Download(){ { curl -kf $1; echo -n " $?" >> badhosts.codes; } }
      #sbc.io URL:  https://github.com/StevenBlack/hosts/blob/master/readme.md
        Download http://sbc.io/hosts/hosts
      #Alozaros URLs: 7/8/18 at https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=315773
        Download http://winhelp2002.mvps.org/hosts.txt
        Download https://someonewhocares.org/hosts/zero/hosts
      #CHEF-KOCH trackers: https://github.com/CHEF-KOCH/NSABlocklist/tree/master/HOSTS/Trackers
        CK=https://raw.githubusercontent.com/CHEF-KOCH/NSABlocklist/master/HOSTS/Trackers
        Download $CK/trackers.txt
        Download $CK/Canvas%20font%20fingerprinting.txt
        Download $CK/audio%20fingerprinting%20pages.txt
        Download $CK/canvas%20fingerprinting%20pages.txt
        Download $CK/webrtc%20tracking.txt
      #youtube from Handley, stuart engineering, barcelona: https://gist.github.com/seanhandley
        Download https://gist.githubusercontent.com/seanhandley/d76c51099a32287c0a9074d5f15ac7d0/raw/2bde83a93e68208585d602df787d782036271438/gistfile1.txt
      #other youtube URLs: https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1186953
        Download https://api.hackertarget.com/hostsearch/?q=googlevideo.com | awk -F , '{print "0.0.0.0",$1}'
        Download https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt | sed '/---/d;s/^/0.0.0.0 &/'
    } 2>badhosts.log \
    | sed 's/\t/ /g; /^0\.0\.0\.0 /!d; s/ *\#.*$//; s/\r//' \
    | sort -u | sed -Ef badhosts.whitelist \
    | cat - badhosts.blacklist >> badhosts
    #defeat redirecting PTR lookups
      A='^Address [0-9]+: '; I='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
      while read D; do
        { nslookup $D 2>/dev/null; echo -n " $?" >>badhosts.codes; } \
        | sed -nE "/$A$I/{s/$A($I).*/\1 $D/p;q}"
      done <badhosts.ptr >>badhosts
    echo '' >> badhosts.codes
    wc -l badhosts \
    | awk '{printf "%s has %d lines, exit codes",$2,$1}' \
    | cat - badhosts.codes \
    | logger -t "startup-code adblocker"
  ) && killall -HUP dnsmasq & )

This script is meant to be run just once, in Startup at boot time. If I don't reboot for a few days, I start to see youtube ads again. I suspect this is because the badhosts line for manifest.google.com has become too old. But modifying this script so that it could be rerun periodically, say by cron, would require some thought. This is because if you use "Forced DNS Redirection," like I do here, nslookup (in the script) will obtain the wrong IP for manifest.google.com (it will obtain 0.0.0.0) if the blocker is already running. On an ordinary linux system, nslookup could be run with a -port=blah argument to get around the forcing, but on dd-wrt nslookup does not accept the -port argument. So this script works best on systems that get rebooted daily or near daily.

_________________
2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Wed Jan 29, 2020 18:35    Post subject: Reply with quote
I just did some tweaking of the short version of my youtube blocker above at https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=322606&start=52. See the edit comment just after the code.
_________________
2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Thu Feb 13, 2020 2:42    Post subject: Reply with quote
@SurprisedItWorks
your script never work with me, in both i got IP 0.0.0.0 so all went down, will be better to specific which router model you have and firmware, i believe this is not for any router. Laughing
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Thu Feb 13, 2020 21:59    Post subject: Reply with quote
Rickz wrote:
@SurprisedItWorks
your script never work with me, in both i got IP 0.0.0.0 so all went down, will be better to specific which router model you have and firmware, i believe this is not for any router. Laughing

As my sig says, I'm on Linksys WRT1900ACSv2 routers. They are pretty fast and have a decent amount of memory, so an older, smaller router might indeed be an issue, especially if you try to keep my long list of Download sites. Maybe commenting out many of the downloads to try a small version would make sense. You also might want to experiment with longer sleep times up front. Some older releases for smaller routers do not have curl on them. If you are in that boat, replace curl -kf with wget -O - (including that final hyphen) in the definition of Download.

I've run this on releases 40009, 40784, and 41954. Haven't seen any build-specific issues.

I'm not in a position to say much more. If you have shell-script skills, it shouldn't be too hard to test it out in pieces in ssh to perhaps discover where the issue lies.

_________________
2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.
Rickz
DD-WRT Novice


Joined: 01 Jan 2020
Posts: 35

PostPosted: Mon Mar 02, 2020 17:45    Post subject: Reply with quote
@SurprisedItWorks

i got the WRT1900ACv2

i edited your script to use it like this:
Quote:
#Youtube adblocker. Requires dnsmasq Add'l Config lines
#"addn-hosts=/tmp/badhosts" and "address=/1e100.net/0.0.0.0"
cat <<'EOF' >/tmp/root/adblocker
#!/bin/sh
cd /tmp
D=manifest.googlevideo.com
DD=$(echo $D | sed 's/\./\\./g')
{ curl -kf http://sbc.io/hosts/hosts
} 2>badhosts.log | sed "s/\t/ /g; /^0\.0\.0\.0 /!d; s/ *\#.*$//; s/\r//; / $DD$/d" | sort -u > badhosts
killall -HUP dnsmasq; sleep 5
A='^Address [0-9]+: '; I='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
nslookup $D 2>/dev/null | sed -nE "/$A$I/{s/$A($I).*/\1 $D/p;q}" >>badhosts
killall -HUP dnsmasq
EOF
chmod +x /tmp/root/adblocker
( sleep 90; /tmp/root/adblocker ) &


how do i know if i have to edit it accordingly your last comment :
Quote:
This code is a stripped-down version of what I've been running successfully for a couple of weeks now, but in stripped-down form it has been tested only modestly. Take a look at the last line of badhosts (perhaps using tail /tmp/badhosts) to check the key manifest.googlevideo.com line. On some earlier dd-wrt builds (even as recently as early 2019), /tmp/root/adblocker will not run the file as a shell script as it should. In that case, do sh /tmp/root/adblocker instead.


how i know if i have to use:
Quote:
sh /tmp/root/adblocker

and which lines i should replace in the script ?

also i have a doubt about which is the best, stripped-down version or should i use the full long version ??

thanks in advance

Laughing
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1447
Location: Appalachian mountains, USA

PostPosted: Tue Mar 03, 2020 17:12    Post subject: Reply with quote
Rickz wrote:
@SurprisedItWorks... i got the WRT1900ACv2... i edited your script to use it like this:
Quote:
#Youtube adblocker. Requires dnsmasq Add'l Config lines
#"addn-hosts=/tmp/badhosts" and "address=/1e100.net/0.0.0.0"
cat <<'EOF' >/tmp/root/adblocker
#!/bin/sh
cd /tmp
D=manifest.googlevideo.com
DD=$(echo $D | sed 's/\./\\./g')
{ curl -kf http://sbc.io/hosts/hosts
} 2>badhosts.log | sed "s/\t/ /g; /^0\.0\.0\.0 /!d; s/ *\#.*$//; s/\r//; / $DD$/d" | sort -u > badhosts
killall -HUP dnsmasq; sleep 5
A='^Address [0-9]+: '; I='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
nslookup $D 2>/dev/null | sed -nE "/$A$I/{s/$A($I).*/\1 $D/p;q}" >>badhosts
killall -HUP dnsmasq
EOF
chmod +x /tmp/root/adblocker
( sleep 90; /tmp/root/adblocker ) &
how do i know if i have to edit it accordingly your last comment :
Quote:
This code is a stripped-down version of what I've been running successfully for a couple of weeks now, but in stripped-down form it has been tested only modestly. Take a look at the last line of badhosts (perhaps using tail /tmp/badhosts) to check the key manifest.googlevideo.com line. On some earlier dd-wrt builds (even as recently as early 2019), /tmp/root/adblocker will not run the file as a shell script as it should. In that case, do sh /tmp/root/adblocker instead.
how i know if i have to use:
Quote:
sh /tmp/root/adblocker
and which lines i should replace in the script ?

also i have a doubt about which is the best, stripped-down version or should i use the full long version ??

thanks in advance

Laughing

Greetings, RickZ. In the CLI, simply do ls -l /tmp/badhosts* after you are sure more than 90 seconds has passed since boot. If the script didn't run (so that you need the sh approach), you'll get a message that there are no such files. (It's also possible that you'll have dnsmasq trouble, since you've told it to look for badhosts. I'm not sure on that point.). But if ls lists /tmp/badhosts and /tmp/badhosts.log, then certainly the script ran and you don't need the sh.

In the latter case do cat /tmp/badhosts.log to have a look at the script's download log. The curl command curl in the script should have written three lines (at least in my version of dd-wrt) to this file, two of header labels and one line showing how the download went. On the left look for 100% of the file to have been downloaded. If that looks good, for a bit more confidence building, do wc -l /tmp/badhosts to see how many lines (one per domain blocked) are in the badhosts[/b] file. Should be thousands I believe, for that particular file. Finally do tail /tmp/badhosts to see the last ten lines of the [i]badhosts file. All the lines except the last should look like "0.0.0.0 " followed by a domain name, and the last line should be some nonzero IP address followed by manifest.googlevideo.com.

Those are the basic checks. Since as presented, that super-abbreviated form of the script does not download the thousands of youtube-specific domains that people identified early in this thread, it may or may not do anything useful for youtube blocking. But it should certainly block a lot of other ad-related nonsense. Try nslookup (I'm not sure of the precise Windows syntax, but it's easy to google) of one of the sites you saw zeros for in the tail... command above to verify that it gives you a 0.0.0.0 IP address. (I don't know that I'd try visiting one in a browser, because some malware sites can abuse a simple visit. No problem if the blocking works, right?)

If the files are not present, before you look at the sh option, try increasing the 90 second number at the end to 300 seconds, reboot, and wait 5 min before checking things out. That'd be just to be sure the problem was not a timing issue.

I haven't waded through the details of your edited version of the script to see how it differs from what I posted, so I can't comment on that. I'm not sure what you are asking when you say "which lines i should replace in the script?" Replace with what goal? As to which version to use. Try this simple version, see if it works for what you want. If youtube is still a problem, I believe with the WRT1900ACv2 you'll be good to try the full version (as that router is almost identical to mine), though be sure you have at least 4K (more would be safer) of free nvram space (see the status page in the GUI) before you try installing it in the Startup section. Really, really bad things happen when you run out of nvram space. I like the long version of the script for the exception lists but also for the greater diagnostics: a [b]badhosts.codes[b] file, a couple of syslog entries, etc. And it is easier to add or delete download sites in that version, so you could cut it down a bit and use only the sbc.io site of your version above plus the youtube-related sites, if you still want to tilt towards the minimal. It'd be easy enough to zero out the whitelists and blacklist and keep only the manifest.google.com entry in the other list as well.

_________________
2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.
SuninderSingh
DD-WRT Novice


Joined: 05 Sep 2017
Posts: 28
Location: IN

PostPosted: Sat Jun 20, 2020 14:10    Post subject: Trying new AdBlock script on TP-Link TL-WR841ND v9 Reply with quote
SurprisedItWorks wrote:
Here is the new, improved version of my adblocker. The reason to use it, even if you want only youtube blocking, is to get the logging and diagnostics and safety features. If you don't like it downloading other block lists, just delete the Download URL lines for the lists you don't want to use! Don't want a blacklist? Delete its entries. I've split the whitelist here into two lists, the WHITE list and the ALLWHITE list. Putting foo.com in the WHITE lists just whitelists foo.com. Putting it in the ALLWHITE list whitelists both foo.com and *.foo.com. Using two lists simplified practical whitelisting. Don't like the whitelists? Delete all entries from those lists. It's fine for all these lists to be empty.

There is a new separate PTRLIST here of sites that need special treatment like we've been giving manifest.google.com. These are ad-related sites that in the public DNS system have reverse lookups that don't point back to the original domain but instead point to weird-looking domain names seem to be somehow useful in their ad systems. Don't want those two other sites in that list? Delete them. However, to block youtube ads, you must keep manifest.google.com in that list.
Code:
#Adblocker.  Requires dnsmasq Add'l Config lines
#"addn-hosts=/tmp/badhosts" and "address=/1e100.net/0.0.0.0"
#Re manifest.googlevideo.com for youtube ad blocker, see
#https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1187268 and
#https://www.reddit.com/r/pihole/comments/9w5swx/i_think_ive_managed_to_block_youtube_ads_with/
( STARTED=/tmp/root/StartedAdBlocker
  [[ -f $STARTED ]] && exit || touch $STARTED
  ( cd /tmp; touch badhosts;
    sleep 30; until ping -c 1 -w 1 &>/dev/null cloudflare.com; do sleep 30; done; sleep 60
    cat <<'ENDPTR' >badhosts.ptr
manifest.googlevideo.com
media.trafficjunky.net
static.trafficjunky.net
ENDPTR
    sed 's/\./\\./g;s/.*/\/ &$\/d/' <<'ENDWHITE' - badhosts.ptr >badhosts.whitelist
ipleak.net
secret.[^g]+oogle.com
ny(mag|post).com
ENDWHITE
    sed 's/\./\\./g;s/.*/\/( |\\.)&$\/d/' <<'ENDALLWHITE' >>badhosts.whitelist
hulu(ad)?.com
ENDALLWHITE
    awk '{print "0.0.0.0 "$1}' <<'ENDBLACK' >badhosts.blacklist
ads.facebook.com
connect.facebook.net
ENDBLACK
    { Download(){ { curl -kf $1; echo -n " $?" >> badhosts.codes; } }
      #sbc.io URL:  https://github.com/StevenBlack/hosts/blob/master/readme.md
        Download http://sbc.io/hosts/hosts
      #Alozaros URLs: 7/8/18 at https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=315773
        Download http://winhelp2002.mvps.org/hosts.txt
        Download https://someonewhocares.org/hosts/zero/hosts
      #CHEF-KOCH trackers: https://github.com/CHEF-KOCH/NSABlocklist/tree/master/HOSTS/Trackers
        CK=https://raw.githubusercontent.com/CHEF-KOCH/NSABlocklist/master/HOSTS/Trackers
        Download $CK/trackers.txt
        Download $CK/Canvas%20font%20fingerprinting.txt
        Download $CK/audio%20fingerprinting%20pages.txt
        Download $CK/canvas%20fingerprinting%20pages.txt
        Download $CK/webrtc%20tracking.txt
      #youtube from Handley, stuart engineering, barcelona: https://gist.github.com/seanhandley
        Download https://gist.githubusercontent.com/seanhandley/d76c51099a32287c0a9074d5f15ac7d0/raw/2bde83a93e68208585d602df787d782036271438/gistfile1.txt
      #other youtube URLs: https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1186953
        Download https://api.hackertarget.com/hostsearch/?q=googlevideo.com | awk -F , '{print "0.0.0.0",$1}'
        Download https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt | sed '/---/d;s/^/0.0.0.0 &/'
    } 2>badhosts.log \
    | sed 's/\t/ /g; /^0\.0\.0\.0 /!d; s/ *\#.*$//; s/\r//' \
    | sort -u | sed -Ef badhosts.whitelist \
    | cat - badhosts.blacklist >> badhosts
    #defeat redirecting PTR lookups
      A='^Address [0-9]+: '; I='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
      while read D; do
        { nslookup $D 2>/dev/null; echo -n " $?" >>badhosts.codes; } \
        | sed -nE "/$A$I/{s/$A($I).*/\1 $D/p;q}"
      done <badhosts.ptr >>badhosts
    echo '' >> badhosts.codes
    wc -l badhosts \
    | awk '{printf "%s has %d lines, exit codes",$2,$1}' \
    | cat - badhosts.codes \
    | logger -t "startup-code adblocker"
  ) && killall -HUP dnsmasq & )

This script is meant to be run just once, in Startup at boot time. If I don't reboot for a few days, I start to see youtube ads again. I suspect this is because the badhosts line for manifest.google.com has become too old. But modifying this script so that it could be rerun periodically, say by cron, would require some thought. This is because if you use "Forced DNS Redirection," like I do here, nslookup (in the script) will obtain the wrong IP for manifest.google.com (it will obtain 0.0.0.0) if the blocker is already running. On an ordinary linux system, nslookup could be run with a -port=blah argument to get around the forcing, but on dd-wrt nslookup does not accept the -port argument. So this script works best on systems that get rebooted daily or near daily.


Hello, I just used above script and its give few errs with wget attach screenshots for reference:-

P.S. - Normally it start in less than 1 min but this time it took almost more than 5 mins.

_________________
>>TP-Link TL-WR841ND v9
>>DD-WRT v3.0-r43397 std (06/13/20)
>>TP-Link TL-WR841ND v9
>>DD-WRT v3.0-r45735 std (02/11/21)
Goto page Previous  1, 2, 3, 4, 5, 6  Next Display posts from previous:    Page 4 of 6
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum