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

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

程序员文章站 2023-01-25 07:54:11
复制代码 代码如下:<%@ language=vbscript %> <% dim strip strip = request("ip") %> &...
复制代码 代码如下:

<%@ language=vbscript %>
<%
dim strip
strip = request("ip")
%>
<form action=? method=post>
输入ip:<input type=text value="<%=strip%>" style="border: #aaaaaa 1px solid;" name="ip">
<input type="submit" value="确定发送">
</form>
<%
if strip="list" then
call listdenyip("2443")
response.end
end if
if strip="query" then
call checkwebsitesetup
response.end
end if
#
if strip<>"" then
call adddenyip("2443",strip)
end if
sub checkwebsitesetup()
set iisobj=getobject("iis://localhost/w3svc")
for each website in iisobj
if website.class="iiswebserver" then
for each b in website.serverbindings
response.write ("server "&website.adspath" has binding"&b)
response.write ("<br>")
next
end if
next
end sub
#
sub listdenyip(strwebno)
set secobj = getobject("iis://localhost/w3svc/"+strwebno+"/root")
set myipsec = secobj.ipsecurity
iplist=myipsec.ipdeny
if ubound(iplist)<0 then
response.write "<br>无数据,请先随便加一条<br>"
exit sub
end if
#
intiplistcount=ubound(iplist)+1
#
for i=0 to ubound(iplist)
response.write i+1
response.write ":"
response.write iplist(i)
response.write "<br>"
next
end sub
sub adddenyip(strwebno,strdenyip)
set secobj = getobject("iis://localhost/w3svc/"+strwebno+"/root")
set myipsec = secobj.ipsecurity
' make sure grantbydefault=true or your changes will not count.
if (false = myipsec.grantbydefault) then
response.write "<br>grantbydefault was not true. setting to true.<br>"
myipsec.grantbydefault = true
end if

iplist=myipsec.ipdeny
if ubound(iplist)<0 then
response.write "<br>无数据,请先随便加一条<br>"
exit sub
end if
#
intiplistcount=ubound(iplist)+1
#
for i=0 to ubound(iplist)
if strdenyip = left(iplist(i),len(strdenyip)) then
response.write "<br>重复数据。<br>"
exit sub
end if
next
redim preserve iplist(intiplistcount)
iplist(intiplistcount)=strdenyip

response.write "新添加:"
response.write strdenyip
response.write "<br>"
myipsec.ipdeny = iplist
secobj.ipsecurity = myipsec
secobj.setinfo
end sub
%>