How To Optimize A Large Hosts File
How, you say? By putting multiple HostNames on the same line! You can put a maximum of nine HostNames on one line. This page describes the format of the HOSTS file in detail: http://publib.boulder.ibm.com/infocenter/systems/topic/com.ibm.aix.files/doc/aixfiles/hosts.htm
A sample line from an optimized HOSTS file looks like this:
127.0.0.1 antispyware2008.name antispyware2008.org antispyware2008a.com antispyware2008buy.com antispyware2008c.com antispyware2008purchase.com antispyware2008soft.com antispyware2008y.com antispywareadaware.com
It sure took a long time to edit the file and put nine HostNames on each line, though. Just kidding! Here is custom awk script to manage my HOSTS file and the part that does the work looks like this:
BEGIN{
printf "127.0.0.1 localhost localhost.localdomain\n"
# add your favorite sites here:
printf "212.56.95.253 hosts-file.net www.hosts-file.net forum.hosts-file.net\n"
}
/^127/||/^0/{
lcase=tolower($2)
if (lcase=="localhost"||lcase=="localhost.localdomain") {next}
if (lcase in j) {next}
j[lcase]
a[++i]=lcase
if (i==9){
printf "127.0.0.1 %s %s %s %s %s %s %s %s %s\n",a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]
i=0
}
}END{
if (i>0){
printf "127.0.0.1"
for (k=1;k<=i;k++) {printf " %s",a[k]}
printf "\n"
}
}
Uh, getting back to the hosts file, I think a few more words would be helpful to the uninitiated. To make this work, you will need an awk interpreter. I have found a very fast one here: http://www.klabaster.com/progs/mawk32.zip.
Unpack it and copy mawk.exe to a directory somewhere in your path.
Copy the script code into a file named hosts.awk or something and then from the command line (or batch file) type:
mawk -f hosts.awk HOSTS > HOSTS_NEW
ren HOSTS HOSTS_OLD
ren HOSTS_NEW HOSTS
SC START DNSCache
ipconfig /displaydns
Each time the HOSTS file is updated you can type:
ipconfig /flushdns
ipconfig /displaydns
The /displaydns command will cause the new HOSTS file to be read and cached, which may take several seconds. Enjoy your faster machine!Smile
a simple app to optimize the hosts file and can be downloaded from here: http://www.mediafire.com/file/u32ygdxhzym/hostsopt.zip.
Instructions:
1. Run hostsopt.exe as administrator;
2. Press the 'Optimize Hosts' button.
And that's all...
Originally posted on the hpHosts Forums. Contents edited for clarity.
 You may not reproduce this article in whole or part without the express permission of the author and MalwareTeks.
REVISED: December 28th, 2009
|