hostsedit.exe a windows command line hosts file editor

This software is released under the GNU GPL (General Public Licence)

Summary

hostsedit.exe is a simple way to add and remove entries to the windows hosts file. If you aren't sure what that means then you probably don't need it. It is used to automate changes to unusual network configurations.

Downloads

Source code, a precompiled exe and a zip are available

Details

It looks for the hosts file under [windows system directory]\devices\etc\hosts then [windows directory]\hosts. If it finds the file then it adds or removes entries as specified by the command line arguments

Basic Options

OpenVPN options

The openvpn-up and openvpn-down options are designed to work as up and down scripts for OpenVPN. A configuration file could look like:

up "hostsedit openvpn-up secureserver"
down "hostsedit openvpn-down secureserver"

This will add and remove a hosts file entry named secureserver associated with the remote IP address of the OpenVPN tunnel. The IP address is read from the environment variables, as under windows the exact position of the parameters passed to the up script can vary depending on the associated adapters name (spaces in the name cause problems)

Alternatives

awk or sed could both edit the hosts file, but neither have a good way to find the file name