The Teamaton tool belt: a collection of small but useful tools for every day development and administration

by Oliver 26. January 2011 20:30

Today: a simple hosts file editor

Today I set up a new project on GitHub: the Teamaton tool belt! It shall serve us as a central store for small tools, probably mostly command-line, built for a single purpose. The first tool in our new tool belt is: HostsEditor.

I wrote this small command line utility after reading this blog post: http://apdubey.blogspot.com/2008/09/edit-host-file-by-batch-file.html. We were looking for an easy way to edit the Windows hosts file from a script for a larger development environment setup that we wanted to fully automate including IIS website, bindings and new entries in the said hosts file. Of course, for a one-timer echo does the job, but don’t try to run the setup script twice on the same maching – you’ll get duplicate entries very quickly.

Reading about how other people are asking the author of the above post how to avoid the duplicates or how to erase entries from the hosts file, I set out to simply write such a utility myself and share it with the rest of the world. If there is one other person out there to whom it will be useful I will be happy.

So, HostsEditor does the following:

  • Adds and removes entries to and from the Windows hosts file.
  • Automatically backs up the original hosts file to hosts.bck.
  • Does not add duplicate entries; instead prints a warning.
  • For usage in automation scripts there is /q switch to suppress all info messages.

hostseditor-usage

That’s all there is to it for now. But there’s more to come!

Stay tuned, Oliver

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.