{"id":13722845,"url":"https://github.com/kevinburke/hostsfile","last_synced_at":"2025-04-13T09:52:58.035Z","repository":{"id":20438397,"uuid":"23715194","full_name":"kevinburke/hostsfile","owner":"kevinburke","description":"go tool for working with /etc/hosts files","archived":false,"fork":false,"pushed_at":"2022-05-22T04:05:18.000Z","size":67,"stargazers_count":142,"open_issues_count":1,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T01:22:05.441Z","etag":null,"topics":["go","hosts","hostseditor","hostsfile"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/kevinburke/hostsfile","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinburke.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-05T19:14:47.000Z","updated_at":"2025-02-18T23:45:16.000Z","dependencies_parsed_at":"2022-07-31T19:48:10.933Z","dependency_job_id":null,"html_url":"https://github.com/kevinburke/hostsfile","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fhostsfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fhostsfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fhostsfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fhostsfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinburke","download_url":"https://codeload.github.com/kevinburke/hostsfile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248695303,"owners_count":21146952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","hosts","hostseditor","hostsfile"],"created_at":"2024-08-03T01:01:33.775Z","updated_at":"2025-04-13T09:52:58.015Z","avatar_url":"https://github.com/kevinburke.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# hostsfile\n\nThis library, and the associated command line binary, will help you manipulate\nyour /etc/hosts file. Both the library and the binary will leave comments\nand other metadata in the /etc/hosts file as is, appending or removing only\nthe lines that you want changed. A description of the API [can be found at\ngodoc][godoc].\n\n## Installation\n\nOn Mac, install via Homebrew:\n\n```\nbrew install kevinburke/safe/hostsfile\n```\n\n\nIf you have a Go development environment, you can install via source code:\n\n    go get github.com/kevinburke/hostsfile@latest\n\n## Command Line Usage\n\nEasily add and remove entries from /etc/hosts.\n\n```\n# Assign 127.0.0.1 to all of the given hostnames\nhostsfile add www.facebook.com www.twitter.com www.adroll.com 127.0.0.1\n# Remove all hostnames from /etc/hosts\nhostsfile remove www.facebook.com www.twitter.com www.adroll.com\n```\n\nYou may need to run the above commands as root to write to `/etc/hosts` (which\nis modified atomically).\n\nTo print the new file to stdout, instead of writing it:\n\n```\nhostsfile add --dry-run www.facebook.com www.twitter.com www.adroll.com 127.0.0.1\n```\n\nYou can also pipe a hostsfile in:\n\n```\ncat /etc/hosts | hostsfile add --dry-run www.facebook.com www.twitter.com www.adroll.com 127.0.0.1\n```\n\nOr specify a file to read from at the command line:\n\n```\nhostsfile add --file=sample-hostsfile www.facebook.com www.twitter.com www.adroll.com 127.0.0.1\n```\n\n## Library Usage\n\nYou can also call the functions in this library from Go code. Here's an example\nwhere a hosts file is read, modified, and atomically written back to disk.\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"log\"\n\t\"net\"\n\t\"os\"\n\n\thostsfile \"github.com/kevinburke/hostsfile/lib\"\n)\n\nfunc checkError(err error) {\n\tif err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n}\n\nfunc main() {\n\tf, err := os.Open(\"/etc/hosts\")\n\tcheckError(err)\n\th, err := hostsfile.Decode(f)\n\tcheckError(err)\n\n\tlocal, err := net.ResolveIPAddr(\"ip\", \"127.0.0.1\")\n\tcheckError(err)\n\t// Necessary for sites like facebook \u0026 gmail that resolve ipv6 addresses,\n\t// if your network supports ipv6\n\tip6, err := net.ResolveIPAddr(\"ip\", \"::1\")\n\tcheckError(err)\n\th.Set(*local, \"www.facebook.com\")\n\th.Set(*ip6, \"www.facebook.com\")\n\th.Set(*local, \"news.ycombinator.com\")\n\th.Set(*ip6, \"news.ycombinator.com\")\n\n\n\t// Write to a temporary file and then atomically copy it into place.\n\ttmpf, err := os.CreateTemp(\"/tmp\", \"hostsfile-temp\")\n\tcheckError(err)\n\n\terr = hostsfile.Encode(tmpf, h)\n\tcheckError(err)\n\n\terr = os.Chmod(tmp.Name(), 0644)\n\tcheckError(err)\n\n\terr = os.Rename(tmp.Name(), \"/etc/hosts\")\n\tcheckError(err)\n\tfmt.Println(\"done\")\n}\n```\n\n[godoc]: https://godoc.org/github.com/kevinburke/hostsfile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fhostsfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinburke%2Fhostsfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fhostsfile/lists"}