Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.31 KB

README.md

File metadata and controls

30 lines (23 loc) · 1.31 KB

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})))