主页 > 知识库 > VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP

VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP

热门标签:网站文章发布 铁路电话系统 呼叫中心市场需求 美图手机 检查注册表项 银行业务 服务器配置 智能手机

复制代码 代码如下:

'/*=========================================================================
' * Intro VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP
' * 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"
'添加要屏蔽的IP或一组计算机,到一个指定站点上
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
'添加要屏蔽的IP或一组计算机,到IIS公共配置,以应用到所有站点
'如果之前对有些站点单独做过屏蔽IP设置,在些设置不会生效,得在总的网站上设置一下,然后覆盖所有子结点
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
'添加允许的IP或一组计算机,到一个指定站点上
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
'添加允许的IP或一组计算机,到IIS公共配置,以应用到所有站点
'如果之前对有些站点单独做过屏蔽IP设置,在些设置不会生效,得在总的网站上设置一下,然后覆盖所有子结点
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
'显示IIS公共配置里禁止访问的IP
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

标签:沈阳 长治 沧州 新疆 上海 河南 乐山 红河

巨人网络通讯声明:本文标题《VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266