pyHostsPatcher is a better way to modify and maintain hosts files, especially when sharing hosts on Internet.
Hosts file is used in operating systems to map hostnames to certain IP addresses. By adding lines into hosts file, users can choose a certain server to connect when access network resources with a hostname. In some countries with strict censorship policy, hosts file offers a way to access blocked web sites sometimes, when combined with HTTPS protocol.
Hosts files in different computers are often unique. Overwriting may not be a good choice. When one or more lines need to be added to a hosts file, at least following things should be done:
Locate hosts file in specific OS;
Remove duplicated hosts lines with same hostnames but are mapped to different IP addresses;
Append new lines.
It's an obstacle to share hosts lines with not-so-powerful users, especially for censorship breaking usage, in which case most of end users can not handle these operations.
NOTICE: Backup files will be generated before any real writing happens. Please keep backups until you are so sure all the patch lines are available and no other negative effects will occur. To restore a backup, you can either rename it to hosts and replace the one in corresponding system folder, or execute pyhostspatch.py or pyhostspatch.exe from command line with --restore parameter immediately followed by the filename of your desired backup.
At present 3 ways are provided to modify your hosts file. However, before patching, a template or guidance script hosts diff file is required. You can find some on our project page, you can also generate one according to hosts information from Internet, which will be discussed in next section.
The simplest (most recommended) way is rename the [hosts diff] file to 'hosts.diff' and put it in the same folder with pyhostspatch.py (source release) or pyhostspatch.exe (win32 binary release), then execute the pyhostspatch.py _or _pyhostspatch.exe. Your confirmation will be required before really write to system hosts file. Answer 'Y' to it if you trust the origin of [hosts diff] file.
You can also drag & release a [hosts diff] file to pyhostspatch.py or pyhostspatch.exe, regardless of what the file name of [hosts diff] is.
For advanced and command-line-only users, some enhancement parameters facilitate modification hosts file or debug the [hosts diff] file. See [command line usage] for more.
NOTICE Administrator priviledge is required to modify hosts file in some OS including Windows(R) 7 and most of POSIX systems.
Hosts files can be released, exchanged and shared in format of [hosts diff] files for universal usability.
See [hosts diff] to know how to compose a diff file. There are also some example diff files in download page.