hosts icon indicating copy to clipboard operation
hosts copied to clipboard

Provide the variants only?

Open rodrigograca31 opened this issue 5 years ago β€’ 6 comments

Hi!

This repo is great but, what if we want to block only porn sites? or only gambling sites? :question:

All of the files have Unified hosts + Variant

I solved this by overengineering a NodeJS solution πŸ˜‚ and then realized there's a very simple way of doing it... :man_facepalming:

Simple way:

diff --unchanged-group-format='' hosts porn > output_file

My NodeJS script: (downloads the hosts file then porn and then goes through all lines and displays the ones that are in the second file but not first.)

const fs = require("fs");
const wget = require("wget-improved");

try {
	let download = wget.download(
		"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
		"hosts",
		{}
	);
	let download2 = wget.download(
		"https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts",
		"porn",
		{}
	);

	const events = [download, download2];
	const promises = events.map((event) => {
		return new Promise((resolve) => {
			event.on("end", (paths) => {
				resolve(paths);
			});
		});
	});

	Promise.all(promises).then((result) => {
		// console.log("both finished", result);

		// read contents of the file
		const data = fs.readFileSync("hosts", "UTF-8");
		const data2 = fs.readFileSync("porn", "UTF-8");

		// split the contents by new line
		const lines = new Set(data.split(/\r?\n/));
		const lines2 = new Set(data2.split(/\r?\n/));

		let count = 0;

		// usint Sets avoids O(n^2)
		lines2.forEach((line2) => {
			if (!lines.has(line2)) {
				console.log(line2);
				count++;
			}
		});

		console.log("# Size diff: ", lines2.size - lines.size);
		console.log("# Diff count: ", count);
	});
} catch (err) {
	console.error(err);
}

Run it: node diff.js > output_file

P.S. Don't forget to: npm i wget-improved

rodrigograca31 avatar Oct 13 '20 13:10 rodrigograca31

Hello! Thank you for opening your first issue in this repo. It’s people like you who make these host files better!

welcome[bot] avatar Oct 13 '20 13:10 welcome[bot]

Hi Rodrigo @rodrigograca31 that's an interesting idea. Nobody has asked for this before, maybe because the base list is so useful?

Stand-alone extension files, in various combinations. I like it.

StevenBlack avatar Oct 13 '20 14:10 StevenBlack

I think, it would be much better to totally refactor hosts file, so instead of putting all in one file, it would be better to split it to a lot of smaller files, that user can select what need, and connect these files as he want. For example I needed to block social webs, so I copied whole that thing with over 12k lines, and then I was delleting specific rules, that I needed to not block... for example I wanted to block all social medias expect twitter and reddit. So I used gedit, where I used replace function to remove rules I wanted to remove. If in repo, we would have folder social medias, and in this folder only social media hosts, and per social media one file, it would help much more. Btw, there can be easy way to create app, that would generate one hosts from these a lot of hosts files. Much easier for users. And easier managing hosts files.

Mlocik97 avatar Nov 05 '20 11:11 Mlocik97

I know....old post and all that,but it's still open so.... Linux to the rescue(no need of such a complicated JavaScripts) πŸ˜‰ : wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts -O porn_only.txt sed -i '0,/^# End yoyo/d; /^#/d; s/ #.*//g; /^$/d' porn_only.txt And Voila...you have yourself one healthy porn only list. Enjoy πŸ‘

dnmTX avatar Oct 20 '21 08:10 dnmTX

I know....old post and all that,but it's still open so.... Linux to the rescue(no need of such a complicated JavaScripts) πŸ˜‰ : wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts -O porn_only.txt sed -i '0,/^# End yoyo/d; /^#/d; s/ #.*//g; /^$/d' porn_only.txt And Voila...you have yourself one healthy porn only list. Enjoy πŸ‘

how make grep domain only without 0.0.0.0 ? becouse i am using for dns rpz

alsyundawy avatar Aug 19 '22 21:08 alsyundawy

I just want to throw my support for this in as well. This is a wonderful project, and having the categories only would be good for situations where blocking all the ads isn't necessarily the goal. I worked in a small library before where this would be handy. This could be used in PiHole or pfBlockerNG as a quick way to help prevent adult content being viewed.

TeleRocker22 avatar Sep 25 '22 00:09 TeleRocker22