All Projects → txn2 → Txeh

txn2 / Txeh

Licence: apache-2.0
Go library and CLI utilty for /etc/hosts management.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Txeh

Kubefwd
Bulk port forwarding Kubernetes services for local development.
Stars: ✭ 2,713 (+1398.9%)
Mutual labels:  networking, devops, homebrew, brew, developer-tools
Bash Toolkit
Este proyecto esá destinado a ayudar a los sysadmin
Stars: ✭ 13 (-92.82%)
Mutual labels:  network, networking, dns, sysadmin
Ceras
Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
Stars: ✭ 374 (+106.63%)
Mutual labels:  binary, network, networking
AutoBrew
AutoBrew: Homebrew deployments made easy
Stars: ✭ 71 (-60.77%)
Mutual labels:  homebrew, brew, developer-tools
Hostctl
Your dev tool to manage /etc/hosts like a pro!
Stars: ✭ 642 (+254.7%)
Mutual labels:  dns, hostsfile, developer-tools
Netaddr
A network address manipulation library for Python
Stars: ✭ 648 (+258.01%)
Mutual labels:  networking, devops, sysadmin
Shaman
Small, lightweight, api-driven dns server.
Stars: ✭ 426 (+135.36%)
Mutual labels:  dns, devops, developer-tools
Carvel Kwt
Kubernetes Workstation Tools CLI
Stars: ✭ 119 (-34.25%)
Mutual labels:  networking, devops, developer-tools
Pnet
High level Java network library
Stars: ✭ 49 (-72.93%)
Mutual labels:  library, network, networking
Librg
🚀 Making multi-player gamedev simpler since 2017
Stars: ✭ 813 (+349.17%)
Mutual labels:  library, network, networking
Macfinder
An iOS Library that helps you find the MAC Address of a specific IP
Stars: ✭ 57 (-68.51%)
Mutual labels:  library, network, networking
Ruffles
Lightweight and fully managed reliable UDP library.
Stars: ✭ 131 (-27.62%)
Mutual labels:  library, network, networking
Sshmon
Manage and monitor SSH connections.
Stars: ✭ 152 (-16.02%)
Mutual labels:  devops, sysadmin
Weihanli.common
common tools,methods,extension methods etc... .net 常用工具类,公共方法,常用扩展方法等,基础类库
Stars: ✭ 152 (-16.02%)
Mutual labels:  utility, library
Php Ip Tools
Useful tools for IP manipulations
Stars: ✭ 152 (-16.02%)
Mutual labels:  utility, library
Ofxgpio
Library C++ for raspberrypi and orangepi, GPIO interfaces compatible with openframeworks.
Stars: ✭ 155 (-14.36%)
Mutual labels:  library, network
Ecs
ECS for Unity with full game state automatic rollbacks
Stars: ✭ 151 (-16.57%)
Mutual labels:  network, networking
Ccna60d
60天通过思科认证的网络工程师考试
Stars: ✭ 155 (-14.36%)
Mutual labels:  network, networking
Dublin Traceroute
Dublin Traceroute is a NAT-aware multipath tracerouting tool
Stars: ✭ 159 (-12.15%)
Mutual labels:  library, network
Npf
NPF: packet filter with stateful inspection, NAT, IP sets, etc.
Stars: ✭ 160 (-11.6%)
Mutual labels:  library, networking

txeh - /etc/hosts mangement

Etc Hosts Management Utility & Go Library

Go Report Card GoDoc

/etc/hosts Management

It is easy to open your /etc/hosts file in text editor and add or remove entries. However, if you make heavy use of /etc/hosts for software development or DevOps purposes, it can sometimes be difficult to automate and validate large numbers of host entries.

txeh was initially built as a golang library to support kubefwd, a Kubernetes port-forwarding utility utilizing /etc/hosts heavily, to associate custom hostnames with multiple local loopback IP addresses and remove these entries when it terminates.

A computer's /etc/hosts file is a powerful utility for developers and system administrators to create localized, custom DNS entries. This small go library and utility were developed to encapsulate the complexity of working with /etc/hosts directly by providing a simple interface for adding and removing entries in a /etc/hosts file.

txeh Utility

Install

MacOS homebrew users can brew install txn2/tap/txeh, otherwise see releases for packages and binaries for a number of distros and architectures including Windows, Linux and Arm based systems.

Complie and run from source (dependencies are vendored):

go run ./util/txeh.go

Use

The txeh CLI application allows command line or scripted access to /etc/hosts file modification.

Example CLI Usage:

 _            _
| |___  _____| |__
| __\ \/ / _ \ '_ \
| |_ >  <  __/ | | |
 \__/_/\_\___|_| |_| v1.1.0

Add, remove and re-associate hostname entries in your /etc/hosts file.
Read more including useage as a Go library at https://github.com/txn2/txeh

Usage:
  txeh [flags]
  txeh [command]

Available Commands:
  add         Add hostnames to /etc/hosts
  help        Help about any command
  remove      Remove a hostname or ip address
  version     Print the version number of txeh

Flags:
  -d, --dryrun         dry run, output to stdout (ignores quiet)
  -h, --help           help for txeh
  -q, --quiet          no output
  -r, --read string    (override) Path to read /etc/hosts file.
  -w, --write string   (override) Path to write /etc/hosts file.
# point the hostnames "test" and "test.two" to the local loopback
sudo txeh add 127.0.0.1 test test.two

# remove the hostname "test"
sudo txeh remove host test

# remove multiple hostnames 
sudo txeh remove host test test2 test.two

# remove an IP address and all the hosts that point to it
sudo txeh remove ip 93.184.216.34

# remove multiple IP addresses
sudo txeh remove ip 93.184.216.34 127.1.27.1

# remove CIDR ranges
sudo txeh remove cidr 93.184.216.0/24 127.1.27.0/28

# quiet mode will suppress output
sudo txeh remove ip 93.184.216.34 -q

# dry run will print a rendered /etc/hosts with your changes without
# saving it.
sudo txeh remove ip 93.184.216.34 -d

# use quiet mode and dry-run to direct the rendered /etc/hosts file
# to another file
sudo txeh add 127.1.27.100 dev.example.com -q -d > hosts.test

# specify an alternate /etc/hosts file to read. writing will
# default to the specified read path.
txeh add 127.1.27.100 dev2.example.com -q -r ./hosts.test

# specify a seperate read and write oath
txeh add 127.1.27.100 dev3.example.com -r ./hosts.test -w ./hosts.test2

txeh Go Library

Dependency:

go get github.com/txn2/txeh

Example Golang Implementation:


package main

import (
    "fmt"
    "strings"

    "github.com/txn2/txeh"
)

func main() {
    hosts, err := txeh.NewHostsDefault()
    if err != nil {
        panic(err)
    }

    hosts.AddHost("127.100.100.100", "test")
    hosts.AddHost("127.100.100.101", "logstash")
    hosts.AddHosts("127.100.100.102", []string{"a", "b", "c"})
    
    hosts.RemoveHosts([]string{"example", "example.machine", "example.machine.example.com"})
    hosts.RemoveHosts(strings.Fields("example2 example.machine2 example.machine.example.com2"))

    
    hosts.RemoveAddress("127.1.27.1")
    
    removeList := []string{
        "127.1.27.15",
        "127.1.27.14",
        "127.1.27.13",
    }
    
    hosts.RemoveAddresses(removeList)
    
    hfData := hosts.RenderHostsFile()

    // if you like to see what the outcome will
    // look like
    fmt.Println(hfData)
    
    hosts.Save()
    // or hosts.SaveAs("./test.hosts")
}

Build Release

Build test release:

goreleaser --skip-publish --rm-dist --skip-validate

Build and release:

GITHUB_TOKEN=$GITHUB_TOKEN goreleaser --rm-dist

License

Apache License 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].