VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP
来源: 阅读:1135 次 日期:2016-07-20 14:19:13
温馨提示: 小编为您整理了“VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP”,方便广大网友查阅!

用ADSI+ASP添加IP到IIS禁止访问列表中

代码如下:

'/*=========================================================================

' * 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

更多信息请查看脚本栏目
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map