Link to home
Start Free TrialLog in
Avatar of younghv
younghvFlag for United States of America

asked on

Automate HOSTS file update process (mvps.org)

I use a modified HOSTS file as one layer of computer security.
The file I use is from this site (http://www.mvps.org/winhelp2002/hosts.htm) and it is updated at least once a month.

My current process is to download the hosts zip file, extract all of the files contained in it, and then execute the mvps.bat file.

Has anyone written (or will anyone write) a script that will:
1.      Navigate to the site;
2.      Download the current hosts.zip file;
3.      Extract all of the files to the default folder; and
4.      Execute the mvps.bat file?

There is no need to compare versions or anything else.
I would just use the Task Scheduler to make it happen on the same day every month.

Thoughts/questions/comments?

Thanks,

Vic
Avatar of sirbounty
sirbounty
Flag of United States of America image

Hmm - I'd have to do some digging, as I think I have had a script that does something similar, but my first thought would be - have you tried Auto It?  You may have heard of it - kind of a macro programming app: http://www.autoitscript.com/autoit3/

Otherwise, I'm sure it could be scripted to just point directly to http://www.mvps.org/winhelp2002/hosts.zip and extract the file(s) as needed.  Not a bad idea for my systems here, so I may just start working on that...probably take me a couple of days though, so someone else may easily provide something for you first...
Well, the program I had won't work for you here.  It's a prompted app for adding new lines to the existing HOSTS.
Still looking though...
Avatar of younghv

ASKER

sb - thanks for responding.
I've been loading it on all the computers I repair and trying to explain to the customers how they can do the update - not much joy with THAT idea.

They don't even update their 'automated' AV programs.

No rush - I'm taking the next week off to head for cooler weather.

Check out the new Zone 'thingy' - if you think I need pointers elsewhere, let me know.

Vic
I can think of a batch file approach, but it's clunky and probably not 100% foolproof...

Something along the lines of - running the link to the text file source,
then doing a recursive scan of temporary internert files until hosts[1].txt is found (at least that's the file name I saw in the few tests I did), then simply overwrite the existing.  Though, this would eliminate the whole batch file that's included with the zip version, that you may need if you're running this against several different OS clients....
Although basic, how about this for a start.
NOTE

@echo off
c:
mkdir c:\hosts
cd c:\hosts
if exist hosts.zip del hosts.zip
rem get wget from http://xoomer.alice.it/hherold/
wget http://www.mvps.org/winhelp2002/hosts.zip 
rem get unzip.exe from ftp://sunsite.icm.edu.pl/pub/unix/archiving/info-zip/WIN32/unz552xN.exe
unzip.exe hosts.zip
copy hosts. %windir%\system32\drivers\etc
mvps
pause
NOTE : unzip.exe and wget need to exist in the system path or the directory you run the batch file from.
Opppsss, remove the copy hosts. %windir%\system32\drivers\etc line
LOL!
OK, updated it to check for errors.
Still basic, but at least it knows if there was a problem now.

@echo off
c:
mkdir c:\hosts
cd c:\hosts
if exist hosts.zip del hosts.zip
rem *** Get wget from http://xoomer.alice.it/hherold/
wget http://www.mvps.org/winhelp2002/hosts.zip 
rem *** Check for Error
if errorlevel 1 goto error
rem *** Get unzip.exe from ftp://sunsite.icm.edu.pl/pub/unix/archiving/info-zip/WIN32/
unzip.exe -o hosts.zip
rem *** Check for Error
if errorlevel 1 goto error

mvps.bat
goto endit

:error
echo An error occurred
pause

:endit
And if your wondering why I only do a if errorlevel 1
As per here http://www.robvanderwoude.com/errorlevel.html
it's all I need to do.

"IF ERRORLEVEL construction has one strange feature, that can be used to our advantage: it returns TRUE if the return code was equal to or higher than the specified errorlevel.

This means most of the time we only need to check IF ERRORLEVEL 1 ... and this will return TRUE for every non-zero return code."

Terry
Avatar of younghv

ASKER

Terry -
Thank you for working through all of this for me.

Let me try to run through it manually and then using Task Scheduler.

It might take me a couple of days - the boss has me packing for our trip right now.

I thought that she was going to do all that, but that's what I get for thinking.

Back as soon as I can.

Vic
No worries at all.

About the only thing I want to add to it is to check if the C:\hosts directory exists in the first place (Get rid of an incorrect error) and turn wget and unzip to quiet mode (But they are good right now to debug and make sure errors are being picked up).
Both wget and unzip are free to use command line tools running under pretty much any version of windows and wget supports a proxy if needed.

Terry
Change

mkdir c:\hosts
to
if not exist c:\hosts\. mkdir c:\hosts


That should do it.

Terry
Mind you I don't think mvps will work too well scheduled as it has a pause at the end.
My one also has a pause if theres an error.
You might want to just copy and paste the contents of mvps into the one that downloads it and remove the pause it has and tell it
set errorlevel = 1
instead of my pause when an error occurs that way task scheduler should pick up it had a problem.
ASKER CERTIFIED SOLUTION
Avatar of qz8dsw
qz8dsw
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of younghv

ASKER

Terry -
Great work!
It does, indeed, 'work a treat'.

If it is OK by you, I will share your work with Mike Burgess (the MS MVP who does the mvps work).

Thanks a lot.

Vic
No worries at all Vic, Glad to help and you can share it with whoever you want.
Might want to add a GPL comment to it for copy and pasting it as wget and info-zip are both GPL but I have no worries at all with the batch file being used by whoever needs it.

Cheers,
Terry