用ADSI+ASP添加IP到IIS禁止訪問列表中

來源:互聯網
上載者:User

注意:執行的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. %>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.