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.
1'Here, we will pretend this is an imported list
2Dim XMLarr(1)
3XMLarr(0) = "65.19.238.21"
4XMLarr(1) = "198.31.175.100"
5
6Set objIIS = GetObject("IIS://localhost/w3svc")
7'careful, this sets IPDENY on every child web
8Set IISipsec = objIIS.IPSecurity
9If (IISipsec.GrantByDefault = True) Then
10 arrIP = IISipsec.IPDeny
11 arrIPSize = UBound(arrIP)
12 For i = 0 To arrIPSize
13 arrIPstring = arrIPstring & "," & arrIP(i) 'going to use for dupes later.
14 Next
15 ReDim Preserve arrIP(arrIPSize + UBound(XMLarr) + 1)
16 For i = 0 To UBound(XMLarr)
17 myNum = arrIPSize + i + 1
18 If InStr(arrIPstring, XMLarr(i)) = 0 Then
19 arrIP(myNum) = XMLarr(i)
20 End If
21 Next
22 IISipsec.IPDeny = arrIP
23 objIIS.IPSecurity = IISipsec
24 objIIS.SetInfo
25End If
26Set IISipsec = Nothing
27Set objIIS = Nothing