HostsCLI Docs

A CLI tool to block / unblock websites using /etc/hosts. Super simple and easily extendable. Also block Ads, Tracking & Malware sites.


Docs Documentation Status
GitHub Issues GitHub Forks GitHub Stars GitHub LICENSE
Travis Requirements Status Coverage Code Climate Issue Count
Thanks Say thanks :)

Docs & Reference


pip install -U hostscli


Type hostscli –help to get a help on all the available commands


Please note that we require `sudo` permissions to change `/etc/hosts` file

List Supported Websites:

List all websites

$ hostscli websites

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


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


Get a list of available websites


A Decorator to check if the given hosts file is writeable or not. If not writeable, it raises a SudoRequiredError.

hostscli.utils.unblock(website, hosts_file)[source]

Remove entries from the host file to unblock specific websites

Custom Errors

Some custom utility functions that we use

exception hostscli.errors.HostsCLIException[source]

Bases: Exception

A Custom Exception class

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:

  1. list_ads -> Domains of known ad servers
  2. list_malwares -> Domins that potentially have malwares
  3. 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/ file for reference