Skip to content

A python script to block ad domains using the system host file

License

Notifications You must be signed in to change notification settings

edieguez/adaway-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AdAway-py is a python 3 script to block ads using the system host file. It works in Linux

How it works?

In GNU/Linux distros exist a file in /etc/hosts (a.k.a. host file that contains domain names associated to an IP. This applies to Windows too, but the file is in a different location. This is a method to resolve hostnames without using Adaway-py download files that contains the hostnames of publicity servers and associate them with an non-existant IP

What advantages does it have?

  • Can block publicity domains or any other
  • You don't need to load ads, so the navigation speed increases
  • It doesn't require additional software
  • It works in all the system, not only in the web browser

Download

  • Clone this repository using git
git clone https://github.com/edieguez/adaway-py.git

How to use it?

Just enter in the script directory and type

sudo ./__main__.py

you can execute it from the outside folder with

sudo python adaway-py

or if you use the compressed file

sudo ./adaway.py

You can use some flags to do specific actions

usage: adaway.py [-h] [-o HOSTS_FILE] [-a | -d | -w host [host ...] | -b host [host ...]]

A python3 script to block ads using the hosts file

options:
  -h, --help          show this help message and exit
  -o HOSTS_FILE       output file
  -a                  apply blocking
  -d                  deactivate blocking
  -w host [host ...]  whitelist one or multiple hosts
  -b host [host ...]  blacklist one or multiple hosts

AdAway-py 1 AdAway-py 2

Configuration

The configuration file is generated in the first run and it looks like this

{
  "blacklist": [
    "www.nsa.gov",
    "somenastydomain.com"
  ],
  "custom_hosts": {
    "mydomain.com": "127.0.0.1",
    "itanimulli.com": "50.63.202.25"
  },
  "host_files": [
    "http://adaway.org/hosts.txt",
    "http://hosts-file.net/ad_servers.asp",
    "http://winhelp2002.mvps.org/hosts.txt",
    "http://someonewhocares.org/hosts/hosts"
  ],
  "whitelist": [
    "adf.ly",
    "www.linkbucks.com"
  ]
}

It contains only four sections

blacklist

A list of domains that the script will block. It allows you to include hosts that are not in the hosts files

custom_host

A dictionary that allows you to personalize your own hosts

host_files

Contains all the source files to block ad domains

whitelist

A list of domains that the script won't block even if they are in one of the host files

About

A python script to block ad domains using the system host file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages