VBScript uses ADSI to add IP addresses that are blocked or allowed to access IIS in batches.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.