Copy Code code as follows:
'/*=========================================================================
' * Intro VBScript use ADSI to bulk add masks or allow access to IP for IIS
' * FileName vbscript-adsi-iis-add-deny-grant-ip-change-metabase.xml.vbs
' *==========================================================================*/
' Adddenyip2all ' 192.168.1.106,255.255.255.0 '
' Adddenyip2all ' 127.0.0.1 '
' Adddenyip ' 123456, ' 127.0.0.1 '
' Add IP or a group of computers to be screened, to a specific site
Sub Adddenyip (strwebno, Strdenyip)
On Error Resume Next
Set secobj = GetObject ("iis://localhost/w3svc/" & Strwebno & "/root")
Set myipsec = secobj.ipsecurity
MyIPSec.GrantByDefault = True
IPList = Myipsec.ipdeny
i = UBound (iplist) + 1
ReDim Preserve IPList (i)
IPList (i) = Strdenyip
Myipsec.ipdeny = IPList
Secobj.ipsecurity = MyIPSec
Secobj.setinfo
End Sub
' Add IP or a group of computers to be screened, to the IIS public configuration to apply to all sites
' If some of the sites have been individually shielded IP settings, in some settings will not take effect, you have to set up on the overall site, and then cover all child nodes
Sub Adddenyip2all (STRDENYIP)
On Error Resume Next
Set secobj = GetObject ("Iis://localhost/w3svc")
Set myipsec = secobj.ipsecurity
MyIPSec.GrantByDefault = True
IPList = Myipsec.ipdeny
i = UBound (iplist) + 1
ReDim Preserve IPList (i)
IPList (i) = Strdenyip
Myipsec.ipdeny = IPList
Secobj.ipsecurity = MyIPSec
Secobj.setinfo
End Sub
' Add an allowed IP or a group of computers to a specified site
Sub Addgrantip (strwebno, Strgrantip)
On Error Resume Next
Set secobj = GetObject ("iis://localhost/w3svc/" & Strwebno & "/root")
Set myipsec = secobj.ipsecurity
MyIPSec.GrantByDefault = False
IPList = Myipsec.ipgrant
i = UBound (iplist) + 1
ReDim Preserve IPList (i)
IPList (i) = Strgrantip
Myipsec.ipgrant = IPList
Secobj.ipsecurity = MyIPSec
Secobj.setinfo
End Sub
' Add allowed IP or a group of computers to the IIS public configuration to apply to all sites
' If some of the sites have been individually shielded IP settings, in some settings will not take effect, you have to set up on the overall site, and then cover all child nodes
Sub Addgrantip2all (Strgrantip)
On Error Resume Next
Set secobj = GetObject ("Iis://localhost/w3svc")
Set myipsec = secobj.ipsecurity
MyIPSec.GrantByDefault = False
IPList = Myipsec.ipgrant
i = UBound (iplist) + 1
ReDim Preserve IPList (i)
IPList (i) = Strgrantip
Myipsec.ipgrant = IPList
Secobj.ipsecurity = MyIPSec
Secobj.setinfo
End Sub
' Show banned IP in the IIS public configuration
Sub Listdenyip ()
Set secobj = GetObject ("Iis://localhost/w3svc")
Set myipsec = secobj.ipsecurity
IPList = Myipsec.ipdeny ' Ipgrant/ipdeny
WScript.Echo Join (IPList, vbCrLf)
' For i = 0 to UBound (iplist)
' WScript.Echo i + 1 & "-->" & IPList (i)
' Next
End Sub