Configure IP and domain restrictions (VBScript)

This code can be found in Chapter 15 of Windows Server 2003 Security Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This code configures IP and domain restrictions for a web site.
' ------ SCRIPT CONFIGURATION ------
strComputer = "<ServerName>"  'e.g. web01.rallencorp.com
strSiteID = "<SiteID>"        'e.g. 1
' ------ END CONFIGURATION ---------
set objWebSite = GetObject("IIS://" & strComputer & "/W3SVC/" & strSiteID)
set objIPRestrict = objWebSite.Get("IPSecurity")
objIPRestrict.IPDeny = Array("10.1.2.0,255.255.255.0","192.168.179.34")
objIPRestrict.DomainDeny = Array("unrulydomain.biz")
objWebSite.IPSecurity = objIPRestrict
objWebSite.SetInfo
WScript.Echo "Successfully set IP and domain restrictions for web site: " & _
             objWebSite.ServerComment

WScript.Echo ""
WScript.Echo "IP Deny:"
arrDeny = objWebSite.Get("IPSecurity").IPDeny
for i = 0 to Ubound(arrDeny)  
  WScript.Echo arrDeny(i)
next  
arrDeny = objWebSite.Get("IPSecurity").DomainDeny
WScript.Echo ""
WScript.Echo "Domain Deny:"
for i = 0 to Ubound(arrDeny)  
  WScript.Echo arrDeny(i)
next

This code has been viewed 1583 times.

New from the creators of TechTasks.com: StatSheet.com