CopyCode The Code is as follows: '/* =================================================== ==========================================
'* Intro VBScript uses ADSI to batch add IP addresses that are blocked or allowed to access 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 the IP address or a group of computers to be shielded to a specified 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 the IP address or a group of computers to be shielded to the IIS public configuration to apply it to all sites.
'If you have previously disabled IP addresses for some sites, these settings will not take effect. You have to set them on the total website and then overwrite all the 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 allowed IP addresses 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 addresses or a group of computers to the IIS public configuration to apply them to all sites
'If you have previously disabled IP addresses for some sites, these settings will not take effect. You have to set them on the total website and then overwrite all the 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
'Display IP addresses that are not allowed to be accessed 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