GitXplorerGitXplorer
j

go-hostsfile

public
64 stars
16 forks
2 issues

Commits

List of commits on branch master.
Unverified
61485ac1fa6ce8e8c6309be1eae651204f5bbdb9

Support Go 1.18

AAkihiroSuda committed 3 years ago
Unverified
f53f85d8b98f8f4925bceab7890a431e2f46c38f

fix(*): Fix condition compile tag

ttosone committed 3 years ago
Unverified
59e7508e09b9e08c57183ae15eabf1b757328ebf

support in-line cooments #5

bbootjp committed 3 years ago
Verified
f581673a59cf19f7ac16c2321791849aaa3b0998

Use UNIX path on all OSs other than Windows and Plan9 (#3)

RRedL0tus committed 4 years ago
Unverified
b7e1e9a6f3e7884c997f676747184931163bfee3

expand GOOS with the BSDs

ffireglow committed 4 years ago
Unverified
8a26595405fb4058a2966e4a16dea1b0ddd5e012

https:// should be removed

ppzghost committed 5 years ago

README

The README file for this repository.

Hostsfile

Documentation Build Status Report Card

The /etc/hosts parsing and resolver library for golang

Hostsfile is a go (golang) package for parsing hosts files and performing reverse IP -> hostname lookups which are file-based (e.g. via /etc/hosts).

This can be helpful to determine if there is a prettier (or known) hostname available for an IP address.

These lookups are "extremely inexpensive" compared to normal IP reverse DNS lookups because no network communication is required, as these lookups are all file-based! Naturally, the (obvious) tradeoff/downside is that this only works in cases where the IP mapping exists in the hostsfile.

Get it

go get -u github.com/jaytaylor/go-hostsfile

Usage

package main

import (
    "fmt"

    "github.com/jaytaylor/go-hostsfile"
)

func main() {
    res, err := hostsfile.ReverseLookup("127.0.0.1")
    if err != nil {
        panic(err)
    }
    fmt.Printf("%v maps 127.0.0.1 to the following names: %v", hostsfile.HostsPath, res)
}

Output:

/etc/hosts maps 127.0.0.1 to the following names: [localhost]

Supported Operating Systems

Tested and verified working on:

  • Linux
  • Mac OS X
  • Windows

It should also support Plan9, though admittedly I don't have a plan9 installation available to verify that one ;)

Unit-tests

Running the unit-tests is straightforward and standard:

go test

License

Permissive MIT license.

Contact

You are more than welcome to open issues and send pull requests if you find a bug or want a new feature.

If you appreciate this library please feel free to drop me a line and tell me! It's always nice to hear from people who have benefitted from my work.

Email: jay at (my github username).com

Twitter: @jtaylor