VBScript: Ban IPs in IIS Programatically

I used the following code a while back as part of a solution to automate the banning of spammers via their IP address.

'Here, we will pretend this is an imported list
Dim XMLarr(1)
XMLarr(0) = ""
XMLarr(1) = ""

Set objIIS = GetObject("IIS://localhost/w3svc") 'careful, this sets IPDENY on every child web
Set IISipsec = objIIS.IPSecurity
If (IISipsec.GrantByDefault = True) Then
arrIP = IISipsec.IPDeny
arrIPSize = ubound(arrIP)
For i = 0 to arrIPSize
arrIPstring = arrIPstring & "," & arrIP(i) 'going to use for dupes later.
ReDim preserve arrIP(arrIPSize + UBound(XMLarr)+1)
for i = 0 to UBound(XMLarr)
myNum = arrIPSize + i+1
If InStr(arrIPstring,XMLarr(i)) = 0 Then
arrIP(myNum) = XMLarr(i)
End If
IISipsec.IPDeny = arrIP
objIIS.IPSecurity = IISipsec
End If
Set IISipsec = nothing
Set objIIS = nothing

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in IIS, Security, VBScript
2 comments on “VBScript: Ban IPs in IIS Programatically
  1. vern says:

    Hey there! Just happened to see a link to your old netnerds blog tonight and ended up here. Good to see you’re back!

    How are you? How is (don’t be mad if I’m wrong) Celia?

    So, I was browsing and I saw this code here, and I was wondering if this could read the list of addresses gathered from the banftpip script?

    Anayway, talk to you later…

  2. vern says:

    Wait, Delia, right?

Leave a Reply

Your email address will not be published. Required fields are marked *