VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP
作者 佚名
来源 ASP编程
浏览
发布时间 2013-07-09
复制代码 代码如下: ''/*========================================================================= '' * 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 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP的所有评论