欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-11-14 11:40:42
复制代码 代码如下:'/*=========================================================================...

复制代码 代码如下:

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