<div dir="ltr">When I read a post on the Globe and Mail today, it popped up a layer to block the content upon detecting ad-blockers. I could only leave or sign in with subscription account...<div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 19, 2017 at 7:51 PM, Khalid Baheyeldin <span dir="ltr"><<a href="mailto:kb@2bits.com" target="_blank">kb@2bits.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>A couple of years ago, I wanted to implement a network wide ad blocking scheme. Since I am using OpenWRT, I came up with the script below, based on some recipes online. <br><br></div><div>The whole idea is to add to dnsmasq a list of domains that are aliased to either 0.0.0.0 or 127.0.0.1. You then make the OpenWRT device your only DNS server. The script updates the list once a week.<br><br></div>For some reason, I never enabled it. Perhaps because uBlock Origin took care of ads on my laptop and my tablet. Or maybe because the list list is over 66,500 long and I was concerned that it would slow my router. I don't remember.<br><br></div>Maybe someone can find this useful. Please report back if you try it.<br><div><div><div><br><font size="1">#!/bin/sh                     <wbr>                              <wbr>               <br>                              <wbr>                              <wbr>               <br># For OpenWRT,                      <wbr>                              <wbr>         <br># Grab and sort a list of adservers and malware hostnames, and block them            <br>                              <wbr>                              <wbr>                         <br># Install this file in /etc/custom/adblock.sh        <wbr>                              <wbr>  <br># Add it to cron by pasting the following line to System -> Scheduled Tasks          <br># 0 4 * * 1 sh /etc/adblock.sh <br><br>URL_LIST="                    <wbr>                              <wbr>               <br><a href="http://pgl.yoyo.org/adservers/serverlist.php?showintro=1;hostformat=hosts;mimetype=plaintext" target="_blank">pgl.yoyo.org/adservers/<wbr>serverlist.php?showintro=1;<wbr>hostformat=hosts;mimetype=<wbr>plaintext</a><br><a href="http://winhelp2002.mvps.org/hosts.txt" target="_blank">winhelp2002.mvps.org/hosts.txt</a><wbr>                              <wbr>                         <br><a href="http://www.malwaredomainlist.com/hostslist/hosts.txt" target="_blank">www.malwaredomainlist.com/<wbr>hostslist/hosts.txt</a>           <wbr>                             <br><a href="http://hosts-file.net/ad_servers.txt" target="_blank">hosts-file.net/ad_servers.txt</a> "                             <wbr>                         <br>                              <wbr>                              <wbr>                         <br>BLOCK_LIST=/etc/custom/block.<wbr>hosts                         <wbr>                          <br>                              <wbr>                              <wbr>                         <br>TMP_LIST=/tmp/block.list      <wbr>                              <wbr>                         <br>                              <wbr>               <br># Check proper DHCP config and, if necessary, update it<br>uci get dhcp.@dnsmasq[0].addnhosts > /dev/null 2>&1 || <br>  uci add_list dhcp.@dnsmasq[0].addnhosts=$<wbr>BLOCK_LIST &&<br>  uci commit                        <wbr>                    <br>                              <wbr>                          <br>CUSTOM_LIST=$(uci get dhcp.@dnsmasq[0].addnhosts)   <wbr>    <br>                              <wbr>                          <br># Delete the old blocked hosts to make room for the updates<br>rm -f $BLOCK_LIST                   <wbr>                       <br>                              <wbr>                             <br># Empty the temp file                          <wbr>            <br>> $TMP_LIST                     <wbr>                           <br>                              <wbr>                             <br># Download and process the files needed to make the lists  <br>for URL in "$URL_LIST"                   <wbr>                  <br>do                            <wbr>                             <br>  wget -qO- "http://$URL" >> $TMP_LIST                   <br>done                          <wbr>                           <br>                              <wbr>                           <br># If we have a custom file, then include it too          <br>if [ -s "$CUSTOM_LIST" ]; then                          <wbr>  <br>  cat $CUSTOM_LIST >> $TMP_LIST                     <wbr>      <br>fi                            <wbr>                            <br>                              <wbr>                            <br># Sort the lists, and remove the Microsoft Carriage Return ^M<br>sort -u $TMP_LIST |                             <wbr>             <br>  sed -e "s/\r//g" > $BLOCK_LIST                   <wbr>          <br>                              <wbr>                               <br># Delete files used to build list to free up the limited space<br>rm -f $TMP_LIST                     <wbr>                          <br>                              <wbr>                              <wbr>  <br># Tell dnsmasq to re-read its configuration                 <wbr>  <br>killall -HUP dnsmasq                       <wbr>                   <br>                              <wbr>                              <wbr>  <br>exit 0</font><br></div></div></div></div>
<br>______________________________<wbr>_________________<br>
kwlug-disc mailing list<br>
<a href="mailto:kwlug-disc@kwlug.org">kwlug-disc@kwlug.org</a><br>
<a href="http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org" rel="noreferrer" target="_blank">http://kwlug.org/mailman/<wbr>listinfo/kwlug-disc_kwlug.org</a><br>
<br></blockquote></div><br></div>