All Projects → kevinburke → hostsfile

kevinburke / hostsfile

Licence: other
go tool for working with /etc/hosts files

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects
Starlark
911 projects

Projects that are alternatives of or similar to hostsfile

Switchhosts
Switch hosts quickly!
Stars: ✭ 15,408 (+12740%)
Mutual labels:  hosts, hostsfile, hostseditor
Python Hosts
a hosts file manager library written in python
Stars: ✭ 90 (-25%)
Mutual labels:  hosts, hostsfile
Funceble
[ARCHIVED] Please report to https://github.com/funilrys/PyFunceble.
Stars: ✭ 25 (-79.17%)
Mutual labels:  hosts, hostsfile
Hmirror
Mirror of multiple third-party blocklists (updated daily).
Stars: ✭ 104 (-13.33%)
Mutual labels:  hosts, hostsfile
Blacklist
Curated and well-maintained hostfile to block ads, tracking, cryptomining, and more! Updated regularly. ⚡🔒
Stars: ✭ 492 (+310%)
Mutual labels:  hosts, hostsfile
Ultimate.hosts.blacklist
The Ultimate Unified Hosts file for protecting your network, computer, smartphones and Wi-Fi devices against millions of bad web sites. Protect your children and family from gaining access to bad web sites and protect your devices and pc from being infected with Malware or Ransomware.
Stars: ✭ 606 (+405%)
Mutual labels:  hosts, hostsfile
local-cname
Helper script to emulate a local CNAME DNS by writing to /etc/hosts
Stars: ✭ 44 (-63.33%)
Mutual labels:  hosts, hostsfile
Google Hosts
Google hosts generator
Stars: ✭ 3,277 (+2630.83%)
Mutual labels:  hosts, hostsfile
Hosts.extras
Extra rules for https://github.com/StevenBlack/hosts project
Stars: ✭ 120 (+0%)
Mutual labels:  hosts, hostsfile
Hostsvn
Hosts block ads of Vietnamese
Stars: ✭ 145 (+20.83%)
Mutual labels:  hosts, hostsfile
pornhosts
Pornhosts a hosts-file formatted file of the RPZ zone file
Stars: ✭ 33 (-72.5%)
Mutual labels:  hosts, hostsfile
Hosts
Python解析域名生成Hosts文件
Stars: ✭ 45 (-62.5%)
Mutual labels:  hosts, hostsfile
Polish Ads Filter
CertyficateIT - Oficjalne polskie filtry do Adblock, uBlock Origin, Adguard
Stars: ✭ 462 (+285%)
Mutual labels:  hosts, hostsfile
Hblock
Improve your security and privacy by blocking ads, tracking and malware domains.
Stars: ✭ 724 (+503.33%)
Mutual labels:  hosts, hostsfile
Wally3k.github.io
Repo for Firebog hosting
Stars: ✭ 427 (+255.83%)
Mutual labels:  hosts, hostsfile
Mobile Hosts
HOSTS files converted or sourced from various filter lists to prevent ads and tracking.
Stars: ✭ 91 (-24.17%)
Mutual labels:  hosts, hostsfile
hosts
🄯Curated lists of hosts files with various domain blocks.🄯
Stars: ✭ 15 (-87.5%)
Mutual labels:  hosts, hostsfile
GameIndustry-hosts-Template
Unique host templates to enhance own privacy in games, websites and regulary software on Desktop and Android devices
Stars: ✭ 25 (-79.17%)
Mutual labels:  hosts, hostsfile
Vagrant Hostmanager
📝 A Vagrant plugin that manages hosts files within a multi-machine environment.
Stars: ✭ 1,442 (+1101.67%)
Mutual labels:  hosts, hostsfile
Vs Shell Format
the shellscript、Dockerfile、properties ...... format extension
Stars: ✭ 176 (+46.67%)
Mutual labels:  hosts, hostsfile

hostsfile

This library, and the associated command line binary, will help you manipulate your /etc/hosts file. Both the library and the binary will leave comments and other metadata in the /etc/hosts file as is, appending or removing only the lines that you want changed. A description of the API can be found at godoc.

Installation

On Mac, install via Homebrew:

brew install kevinburke/safe/hostsfile

If you have a Go development environment, you can install via source code:

go get github.com/kevinburke/hostsfile@latest

Command Line Usage

Easily add and remove entries from /etc/hosts.

# Assign 127.0.0.1 to all of the given hostnames
hostsfile add www.facebook.com www.twitter.com www.adroll.com 127.0.0.1
# Remove all hostnames from /etc/hosts
hostsfile remove www.facebook.com www.twitter.com www.adroll.com

You may need to run the above commands as root to write to /etc/hosts (which is modified atomically).

To print the new file to stdout, instead of writing it:

hostsfile add --dry-run www.facebook.com www.twitter.com www.adroll.com 127.0.0.1

You can also pipe a hostsfile in:

cat /etc/hosts | hostsfile add --dry-run www.facebook.com www.twitter.com www.adroll.com 127.0.0.1

Or specify a file to read from at the command line:

hostsfile add --file=sample-hostsfile www.facebook.com www.twitter.com www.adroll.com 127.0.0.1

Library Usage

You can also call the functions in this library from Go code. Here's an example where a hosts file is read, modified, and atomically written back to disk.

package main

import (
	"bytes"
	"fmt"
	"log"
	"net"
	"os"

	hostsfile "github.com/kevinburke/hostsfile/lib"
)

func checkError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	f, err := os.Open("/etc/hosts")
	checkError(err)
	h, err := hostsfile.Decode(f)
	checkError(err)

	local, err := net.ResolveIPAddr("ip", "127.0.0.1")
	checkError(err)
	// Necessary for sites like facebook & gmail that resolve ipv6 addresses,
	// if your network supports ipv6
	ip6, err := net.ResolveIPAddr("ip", "::1")
	checkError(err)
	h.Set(*local, "www.facebook.com")
	h.Set(*ip6, "www.facebook.com")
	h.Set(*local, "news.ycombinator.com")
	h.Set(*ip6, "news.ycombinator.com")


	// Write to a temporary file and then atomically copy it into place.
	tmpf, err := os.CreateTemp("/tmp", "hostsfile-temp")
	checkError(err)

	err = hostsfile.Encode(tmpf, h)
	checkError(err)

	err = os.Chmod(tmp.Name(), 0644)
	checkError(err)

	err = os.Rename(tmp.Name(), "/etc/hosts")
	checkError(err)
	fmt.Println("done")
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].