Skip to content

Instantly share code, notes, and snippets.

@Explosion-Scratch
Last active March 16, 2023 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Explosion-Scratch/87f9aa1972bc0b19217b402d731056d8 to your computer and use it in GitHub Desktop.
Save Explosion-Scratch/87f9aa1972bc0b19217b402d731056d8 to your computer and use it in GitHub Desktop.
Generate hosts file with IPv4 and IPv6 support, mac
const fs = require("fs");
const a = require("child_process");
const excluded = [
// Breaks google drive
"clients6.google.com",
];
(async () => {
const hostname = a.execSync("hostname").toString().trim();
let header = `# Hosts file, → Autogenerated at ${new Date().toString()}
# Generated by ${__filename} (${hostname.split(".")[0]})
# BEGIN HEADER
127.0.0.1 localhost ${hostname}
255.255.255.255 broadcasthost
::1 localhost ${hostname}
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
# END HEADER`;
// let blacklist = await fetch("https://scripttiger.github.io/alts/4_6/blacklist-fg.txt").then(r => r.text())
let youtube = await fetch(
"https://raw.githubusercontent.com/ewpratten/youtube_ad_blocklist/master/blocklist.txt"
).then((r) => r.text());
let youtube2 = await fetch(
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/GoodbyeAds-YouTube-Adblock-Extension/hosts"
)
.then((r) => r.text())
.then((text) => {
return text
.split("N S")[1]
.split("#")[1]
.split("\n")
.slice(1)
.map((i) => i.replace("0.0.0.0 ", ""));
});
let spotify = await fetch(
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/GoodbyeAds-Spotify-AdBlock-Extension/hosts"
)
.then((r) => r.text())
.then((text) => {
return text
.split("N S")[1]
.split("#")[1]
.split("\n")
.slice(1)
.map((i) => i.replace("0.0.0.0 ", ""));
});
let morehosts = [
await fetch(
"https://raw.githubusercontent.com/liamengland1/mischosts/master/whiteops-hosts"
).then((r) => r.text()),
await fetch(
"https://raw.githubusercontent.com/liamengland1/mischosts/master/apple-telemetry"
).then((r) => r.text()),
]
.map((i) => {
return i
.split("\n")
.filter((j) => !j.startsWith("#"))
.map((i) => i.replace("0.0.0.0 ", "").trim());
})
.flat();
youtube = [...youtube.split("\n"), ...youtube2, ...spotify, ...morehosts]
.filter((i) => i.trim().length)
.filter((i) => !excluded.includes(i))
.map((i) => {
i = i.trim();
return `0.0.0.0 ${i}\n:: ${i}`;
})
.join("\n");
const other = `\n\n# YOUTUBE BLACKLIST\n\n${youtube}\n\n`;
fs.writeFileSync("/etc/hosts", `${header}\n\n${other}`); // `# OTHER BLACKLIST\n\n${blacklist}`
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment