HostsCLI Docs¶
A CLI tool to block / unblock websites using /etc/hosts. Super simple and easily extendable. Also block Ads, Tracking & Malware sites.
Links¶
Docs Link | http://hostscli.readthedocs.io/ |
---|---|
GitHub Link | https://github.com/dhilipsiva/hostscli |
PyPI Link | https://pypi.python.org/pypi/hostscli |
Badges¶
Docs | |
---|---|
GitHub | |
Tests | |
Thanks |
Docs & Reference¶
Installation¶
pip install -U hostscli
Help¶
Type hostscli –help to get a help on all the available commands
Usage¶
Please note that we require `sudo` permissions to change `/etc/hosts` file
Block Websites¶
To block facebook:
$ sudo hostscli block facebook
To block facebook & youtube:
$ sudo hostscli block facebook,youtube
Unblock Websites¶
To unblock facebook:
$ sudo hostscli unblock facebook
To unblock facebook & youtube:
$ sudo hostscli unblock facebook,youtube
Block All supported Websites¶
Block all available
$ sudo hostscli block_all
Use –ignore ot -i to ignore websites while blocking.
$ sudo hostscli block_all -i facebook,google
Unblock All supported Websites¶
Ubnlock all supported
$ sudo hostscli unblock_all
Use –ignore ot -i to ignore websites while ubblocking.
$ sudo hostscli unblock_all -i facebook,google
Built-in utility functions¶
Some utility functions that gets our work done
-
hostscli.utils.
block
(website, hosts_file)[source]¶ Add entries into the host file to block specific websites
-
hostscli.utils.
get_lines
(website)[source]¶ Get a list of lines of a specific website to append to / remove from the hosts files
raise WebsiteImportError if a website is not available
Custom Errors¶
Some custom utility functions that we use
-
exception
hostscli.errors.
SudoRequiredError
[source]¶ Bases:
hostscli.errors.HostsCLIException
An error raised when the given hosts files is not writable. “sudo” permissions are required to run this command.
-
exception
hostscli.errors.
WebsiteImportError
[source]¶ Bases:
hostscli.errors.HostsCLIException
An error to raise when no Domain list found for given website
Special Lists¶
I have compiled few special lists from various sources to block Ads, Tracking & Disturbing sites.
All the website list that starts with list_ is a special list.
So far, I have these lists:
- list_ads -> Domains of known ad servers
- list_malwares -> Domins that potentially have malwares
- list_misc -> Sites that may have offensive / disturbing content.
These lists can be blocked / unblocked like you do with other websites
$ sudo hostscli block list_ads
Indices and tables¶
More websites?¶
If you need to add more websites, just create a <website>.py
file in hostscli/websites/ directory with list of domains declared as variable DOMAINS.
Please look at hostscli/websites/facebook.py file for reference
Credits¶
Here are some of the list where I borrowed domains from:
https://github.com/jmdugan/blocklists
http://www.malwaredomainlist.com/hostslist/hosts.txt
http://winhelp2002.mvps.org/hosts.txt
http://someonewhocares.org/hosts/hosts
http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&mimetype=plaintext