https://github.com/b0ch3nski/go-hosts-file
Yet another Golang library for hosts file manipulation.
https://github.com/b0ch3nski/go-hosts-file
etc-hosts golang hosts hosts-file hostsfile
Last synced: 3 months ago
JSON representation
Yet another Golang library for hosts file manipulation.
- Host: GitHub
- URL: https://github.com/b0ch3nski/go-hosts-file
- Owner: b0ch3nski
- License: apache-2.0
- Created: 2024-02-04T21:03:17.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-04T21:10:18.000Z (over 1 year ago)
- Last Synced: 2025-02-15T14:16:26.845Z (5 months ago)
- Topics: etc-hosts, golang, hosts, hosts-file, hostsfile
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-hosts-file
[](LICENSE)
[](https://github.com/b0ch3nski/go-hosts-file/releases)
[](https://pkg.go.dev/github.com/b0ch3nski/go-hosts-file)
[](https://goreportcard.com/report/github.com/b0ch3nski/go-hosts-file)
[](https://github.com/b0ch3nski/go-hosts-file/issues)
[](https://sourcegraph.com/github.com/b0ch3nski/go-hosts-file)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
```go
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})))
```