Skip to content

Yet another Golang library for hosts file manipulation.

License

Notifications You must be signed in to change notification settings

b0ch3nski/go-hosts-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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