[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Automate HOSTS file update process (mvps.org)

Posted on 2007-08-04
17
Medium Priority
?
275 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:younghv
  • 11
  • 3
  • 3
17 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 19632052
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...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 19632092
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...
0
 
LVL 38

Author Comment

by:younghv
ID: 19632094
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 67

Expert Comment

by:sirbounty
ID: 19632129
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....
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632137
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
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632141
NOTE : unzip.exe and wget need to exist in the system path or the directory you run the batch file from.
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632144
Opppsss, remove the copy hosts. %windir%\system32\drivers\etc line
LOL!
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632237
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
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632240
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
0
 
LVL 38

Author Comment

by:younghv
ID: 19632263
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
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632271
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
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632276
Change

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


That should do it.

Terry
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632289
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.
0
 
LVL 15

Accepted Solution

by:
qz8dsw earned 2000 total points
ID: 19632613

Here you go, all changes in and tested.
Task scheduler picks up when it fails or succeeds.
It produces an error.log if it strikes and error telling you what step it fails on.

The only thing left to do is to remove the pause from MVPS.bat for task scheduling or merge their move function into the 1 batch file.

@echo off
c:
if not exist c:\hosts\. mkdir c:\hosts
cd c:\hosts
if exist hosts.zip del hosts.zip
rem *** Get wget from http://xoomer.alice.it/hherold/
set place="Transfer"
wget -q http://www.mvps.org/winhelp2002/hosts.zip > NUL
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/
set place="Unzip"
unzip.exe -o -q hosts.zip
rem *** Check for Error
if errorlevel 1 goto error
set place="Move hosts"
call mvps.bat
goto endit

:error
echo An error occurred in %place% >> Error.log
exit 1

:endit
exit 0
0
 
LVL 15

Assisted Solution

by:qz8dsw
qz8dsw earned 2000 total points
ID: 19632632
I'd recommend putting wget.exe and unzip.exe in the system path somewhere or changing the wget and unzip lines to include the full path to where the exe's reside, but asides from that should work a treat.

Terry
0
 
LVL 38

Author Comment

by:younghv
ID: 19632717
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
0
 
LVL 15

Expert Comment

by:qz8dsw
ID: 19632854
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
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to dynamically set the form action using jQuery.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question