LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

C# IIS站點(diǎn)限制特定的IP操作

admin
2022年6月11日 14:52 本文熱度 1584

using System;
using System.DirectoryServices;
using System.Reflection;
//using mscorlib;

namespace ConfigIIS
{
 /// <summary>
 /// Small class containing methods to configure IIS.
 /// </summary>
 class class1
 {
  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   try
   {
    // retrieve the directory entry for the root of the IIS server
    System.DirectoryServices.DirectoryEntry IIS = new System.DirectoryServices.DirectoryEntry("IIS://localhost/w3svc/1/root");

    // retrieve the list of currently denied IPs
    Console.WriteLine("Retrieving the list of currently denied IPs.");

    // get the IPSecurity property
    Type typ = IIS.Properties["IPSecurity"][0].GetType();
    object IPSecurity = IIS.Properties["IPSecurity"][0];

    // retrieve the IPDeny list from the IPSecurity object
    Array origIPDenyList = (Array) typ.InvokeMember("IPDeny",
     BindingFlags.DeclaredOnly |
     BindingFlags.Public | BindingFlags.NonPublic |
     BindingFlags.Instance | BindingFlags.GetProperty, null, IPSecurity, null);

    // display what was being denied
    foreach(string s in origIPDenyList)
     Console.WriteLine("Before: " + s);

    // check GrantByDefault.  This has to be set to true, or what we are doing will not work.
    bool bGrantByDefault = (bool) typ.InvokeMember("GrantByDefault",
     BindingFlags.DeclaredOnly |
     BindingFlags.Public | BindingFlags.NonPublic |
     BindingFlags.Instance | BindingFlags.GetProperty, null, IPSecurity, null);

    Console.WriteLine("GrantByDefault = " + bGrantByDefault);
    if(!bGrantByDefault)
    {
     typ.InvokeMember("GrantByDefault",
      BindingFlags.DeclaredOnly |
      BindingFlags.Public | BindingFlags.NonPublic |
      BindingFlags.Instance | BindingFlags.SetProperty, null, IPSecurity, new object[] {true});
    }

    // update the list of denied IPs.  This is a complete replace.  If you want to maintain what
    // was already being denied, you need to make sure those IPs are in here as well.  This area
    // will be where you will most likely modify to your needs as this is just an example.
    Console.WriteLine("Updating the list of denied IPs.");
    object[] newIPDenyList = new object[4];
    newIPDenyList[0] = "192.168.1.477, 255.255.255.0";
    newIPDenyList[1] = "192.168.1.76, 255.255.255.0";
    newIPDenyList[2] = "192.168.1.467, 255.255.255.0";
    newIPDenyList[3] = "192.168.1.106, 255.255.255.0";
    Console.WriteLine("Calling SetProperty");

    // add the updated list back to the IPSecurity object
    typ.InvokeMember("IPDeny",
     BindingFlags.DeclaredOnly |
     BindingFlags.Public | BindingFlags.NonPublic |
     BindingFlags.Instance | BindingFlags.SetProperty, null, IPSecurity, new object[] {newIPDenyList});
           
    IIS.Properties["IPSecurity"][0] = IPSecurity;           
    Console.WriteLine("Commiting the changes.");

    // commit the changes
    IIS.CommitChanges();
    IIS.RefreshCache();

    // check to see if the update took
    Console.WriteLine("Checking to see if the update took.");
    IPSecurity = IIS.Properties["IPSecurity"][0];
    Array y = (Array) typ.InvokeMember("IPDeny",
     BindingFlags.DeclaredOnly |
     BindingFlags.Public | BindingFlags.NonPublic |
     BindingFlags.Instance | BindingFlags.GetProperty, null, IPSecurity, null);
    foreach(string s in y)
     Console.WriteLine("After:  " + s);
   }
   catch (Exception e)
   {
    Console.WriteLine("Error: " + e.ToString());
   }
  }
 }
}


該文章在 2022/6/11 14:52:13 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
亚洲精品视频福利网 | 亚洲中文字幕页面 | 亚洲午夜国内自产拍在线观看 | 夜鲁夜鲁很鲁在线视频视频 | 亚洲影院午夜在线观看 | 五月天Av在线 |