npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hosts-blocker

v0.2.7

Published

Block ads, malware and spyware using the hosts file

Downloads

32

Readme

Hosts-Blocker

npm version Build Status Coverage Status Dependency Status

Hosts-Blocker can be used to block ads, malware and spyware using the hosts file.

Hosts-Blocker comes with a simple command line tool called nhb (node hosts blocker) that can do two things for you:

  1. It downloads, merges and sorts hosts files from a configurable list of URLs and generates a new hosts file that aggregates the content of all downloaded hosts files.
  2. It runs a small HTTP server that "catches" the redirected HTTP requests.

Installation

The recommended way of installing hosts-blocker is by using using npm:

$ npm install -g hosts-blocker

This will install the nhb executable in your $PATH.

Usage

Configuring Hosts-Blocker

First of all you have to configure a hosts-list and an optional whitelist. You may start with the provided example files:

The hosts-list contains a list of URLs (i.e., one URL per line) of hosts files to be downloaded, merged and sorted.

The whitelist contains a list of hostname patterns (i.e., one pattern per line) to be excluded from the generated hosts file. A hostname pattern can either be a simple string or a regular expression.

In this example, we will put both files into the directory /etc/hosts-blocker (i.e., /etc/hosts-blocker/list and /etc/hosts-blocker/whitelist).

Configuring Dnsmasq

First, add the following line to /etc/dnsmasq.conf:

addn-hosts=/etc/hosts.block

This instructs dnsmasq to use /etc/hosts.block as an additional hosts file (besides the ordinary /etc/hosts). Don't forget to reload dnsmasq for activating this new setting!

Generating a hosts file

Next, you can then use the following command to generate the /etc/hosts.block file and tell dnsmasq to reload all registered hosts files (using killall -HUP dnsmasq):

nhb generate \
  --hosts-list /etc/hosts-blocker/list \
  --whitelist /etc/hosts-blocker/whitelist \
  --destination-ip 127.1.1.1 \
  --ui-hostname hosts-blocker.local \
  --output /etc/hosts.block \
&& killall -HUP dnsmasq

You may also want to run this command regularly (e.g., weekly or even daily) using cron.

Starting the catch-all HTTP server

Finally, you may want to start the catch-all HTTP server using the following command:

nhb server \
    --listen-ip 127.1.1.1 \
    --ui-hostname hosts-blocker.local

This HTTP server will "gracefully" return a HTTP 204 (No Content) for any request to any blocked hostname. For example, if the hostname ads.somecompany.com is contained in the blocked hosts file (e.g., /etc/hosts.block) then any request like GET http://ads.somecompany.com/banner.png will return HTTP 204 (No Content).

Note that the (rudimentary) Web-UI, which is available at http://hosts-blocker.local, can be used to get a live view of blocked requests.