VBScript: Dump IP Restriction and clean IIS logfiles

VBScript: Dump IP Restriction and clean IIS logfiles

Hi all,

First of would like to thx Outsystems team for all the great support and time to help us with our Outsystem deployment. Specially Paulo Silva's effort to keep things up and straight. Cheers Paulo!

After the greetings, I'd like to share a couple of scriptlets* I've made on my own which have proven to be very helpful in couple of situations.

* Copy and past code to a .vbs file, just double-click to execute

Dump IP restrictions:
The first one dumps all IP Restrictions on all IIS virtual directories to an text file. The script has the 1st IIS instance (default web site) hard-coded, but you can easily change for any instance or implement an loop trough the web-sites collection. The final output is friendly text file named dump.IP.restrictions.output.


Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set File = fso.CreateTextFile("dump.IP.restrictions.output", true)

Dim IPList
' If you have adminstrative rights to the remote server you may
' change localhost for any valid hostname and execute the script
' in your own machine instead of locally on the server
Set IISObject = GETObject("IIS://localhost/w3svc/1/root")

For Each SiteDir in IISObject
Set IPSecurity = SiteDir.Get("IPSecurity")

Redim IPList(10000)
IPList = IPSecurity.IPGrant

If (IPSecurity.GrantByDefault = True) Then
GrantSituation = "Granted by Default"
GrantSituation = UBound(IPList)+1 & " IP Addresses Granted"
End If

File.Writeline ("# /" & Mid(SiteDir.Name & String(30, " "),1,30) & " : "& GrantSituation)
For pos = lbound(IPList) to UBound(IPList)

' End

Clean Logfiles:
The second script simply cleans IIS logfiles based upon the number days you wish files to stay on the server, all files older that max_days will be deleted. Put this scripts to run as a scheduled task and you'll save lots of headaches and server hd space automatically :-)

On Error Resume Next
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
' You may want to create here as many calls as websites you have configured
' on your IIS server.
CleanLogDir "C:\WINNT\system32\LogFiles\W3SVC1", max_days
Set fso = Nothing

Sub CleanLogDir(path, DateLimit)
Dim folder, F
Set folder = fso.GetFolder(path)
Set F = folder.Files
For Each f1 in F
If DateDiff("d", f1.DateLastModified, Now) >= DateLimit Then
End If
End Sub

Hope this help you folks!

Arley Silveira.
Hi Arley,

Thank you for your compliment.

These scripts are very useful for production environments.
Specially "Clean Logfiles" that is a maintenance script that will prevent lack of disk space, since Internet Information Server (IIS) doesn't have a feature that cleans old log files.

Paulo Silva