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

注意:执行的ASP文件需要管理员权限

 

  1. <%@ Language=VBScript %>
  2. <%
  3. Dim strIP
  4. strIP = request("IP")
  5. %>
  6. <FORM action=? method=post>
  7. 输入IP:<input type=text value="<%=strIP%>" style="BORDER: #AAAAAA 1px solid;" name="IP">
  8. <input type="submit" value="确定发送">
  9. </FORM> 
  10. <%
  11. if strIP="list" then
  12.     Call ListDenyIP("2443")
  13.     response.end
  14. end if
  15. if strIP="query" then
  16.     Call CheckWebSiteSetup
  17.     response.end
  18. end if
  19. if strIP<>"" then
  20.     Call AddDenyIP("2443",strIP)
  21. end if
  22. Sub CheckWebSiteSetup()
  23.     Set IISOBJ=GetObject("IIS://LocalHost/W3SVC")
  24.     for each website in IISOBJ 
  25.     if website.Class="IIsWebServer" then
  26.     for each b in website.ServerBindings
  27.     response.write ("Server "&Website.AdsPath" has binding"&b)
  28.     response.write ("<br>")
  29.     next
  30.     end if
  31.     next
  32. end sub
  33. Sub ListDenyIP(strWebNo)
  34.     set SecObj = GETObject("IIS://LocalHost/W3SVC/"+strWebNo+"/Root"
  35.     set MyIPSec = SecObj.IPSecurity
  36.     IPList=MyIPSec.IPDeny
  37.     if ubound(IPList)<0 then
  38.         response.write "<BR>无数据,请先随便加一条<BR>"
  39.         exit sub
  40.     end if
  41.     intIPListCount=ubound(IPList)+1
  42.     for i=0 to ubound(IPList)
  43.         response.write i+1
  44.         response.write ":"
  45.         response.write IPList(i)
  46.         response.write "<br>"
  47.     next
  48. end sub
  49. Sub AddDenyIP(strWebNo,strDenyIp)
  50.     set SecObj = GETObject("IIS://LocalHost/W3SVC/"+strWebNo+"/Root"
  51.     set MyIPSec = SecObj.IPSecurity
  52.       ' Make sure GrantByDefault=TRUE or your changes will not count.  
  53.     If (FALSE = MyIPSec.GrantByDefault) Then 
  54.         Response.Write "<BR>GrantByDefault was not TRUE. Setting to TRUE.<BR>" 
  55.         MyIPSec.GrantByDefault = TRUE 
  56.     End If 
  57.     
  58.     IPList=MyIPSec.IPDeny
  59.     if ubound(IPList)<0 then
  60.         response.write "<BR>无数据,请先随便加一条<BR>"
  61.         exit sub
  62.     end if
  63.     intIPListCount=ubound(IPList)+1
  64.     for i=0 to ubound(IPList)
  65.         if strDenyIp = left(IPList(i),len(strDenyIp)) then
  66.             response.write "<BR>重复数据。<BR>"
  67.             exit sub
  68.         end if
  69.     next
  70.     redim Preserve IPList(intIPListCount)
  71.     IPList(intIPListCount)=strDenyIp
  72.     
  73.         response.write "新添加:"
  74.         response.write strDenyIp
  75.         response.write "<br>"
  76.     MyIPSec.IPDeny = IPList
  77.     SecObj.IPSecurity = MyIPSec 
  78.     SecObj.Setinfo
  79. end sub
  80. %>
posted @   林建彧  阅读(86)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix

欢迎光临个人主站:70apps.com,方便分享代码、截图的小工具 DevShots

点击右上角即可分享
微信分享提示