Giter Site home page Giter Site logo

go-hostsfile's Introduction

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 https://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

go-hostsfile's People

Contributors

jaytaylor avatar sionleroux avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.