/go-hosts-file

Yet another Golang library for hosts file manipulation.

Primary LanguageGoApache License 2.0Apache-2.0

go-hosts-file

license release go.dev goreportcard issues sourcegraph

Yet another Golang library for hosts file manipulation. Written for my own purposes but can be easily adopted for multiple other use cases like merging hosts files, removing duplicates, validating, reverse lookups etc.

install

go get github.com/b0ch3nski/go-hosts-file

example

hostsFile, _ := os.Open("/etc/hosts")

h := hosts.New()
h.Read(hostsFile)
h.Add(netip.AddrFrom4([4]byte{8, 8, 8, 8}), "google.com")

fmt.Print(&h)
fmt.Println(h.GetIP("localhost"))
fmt.Println(h.GetAlias(netip.AddrFrom4([4]byte{127, 0, 0, 1})))