Use ADSI + ASP to add IP addresses to the IIS Access prohibited list

Source: Internet
Author: User

Note: administrator permissions are required for the ASP file to be executed.

 

  1. <% @ Language = VBScript %>
  2. <%
  3. Dim strip
  4. Strip = request ("ip ")
  5. %>
  6. <Form action =? Method = post>
  7. Input IP address: <input type = text value = "<% = strip %>" style = "border: # aaaaaa 1px solid;" name = "ip">
  8. <Input type = "Submit" value = "confirm to send">
  9. </Form>
  10. <%
  11. If strip = "list" then
  12. Call listdenyips ("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> no data, please add one <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. Iplist = myipsec. ipdeny
  58. If ubound (iplist) <0 then
  59. Response. Write "<br> no data, please add one <br>"
  60. Exit sub
  61. End if
  62. Intiplistcount = ubound (iplist) + 1
  63. For I = 0 to ubound (iplist)
  64. If strdenyip = left (iplist (I), Len (strdenyip) then
  65. Response. Write "<br> duplicate data. <Br>"
  66. Exit sub
  67. End if
  68. Next
  69. Redim preserve iplist (intiplistcount)
  70. Iplist (intiplistcount) = strdenyip
  71. Response. Write "added :"
  72. Response. Write strdenyip
  73. Response. Write "<br>"
  74. Myipsec. ipdeny = iplist
  75. Secobj. ipsecurity = myipsec
  76. Secobj. setinfo
  77. End sub
  78. %>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.