VBScript: Ban IPs in IIS Programatically

Filed under: IIS, Quick Code, Security, VBScript — Written by Chrissy on Wednesday, April 26th, 2006 @ 11:52 pm

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) = "65.19.238.21"
XMLarr(1) = "198.31.175.100"
 
  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.
        Next
          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
            Next
          IISipsec.IPDeny = arrIP
          objIIS.IPSecurity = IISipsec
          objIIS.SetInfo
    End If
  Set IISipsec = nothing
  Set objIIS = nothing
2 Comments   -
  • Comment by vern | August 12, 2006 @ 10:41 pm

    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...

  • Comment by vern | August 12, 2006 @ 10:41 pm

    Wait, Delia, right?

Leave your comment