簡體   English   中英

如何通過C#檢查遠程服務器上的Windows防火牆狀態

[英]How can I check windows firewall status on remote server via C#

如何通過C#檢查遠程服務器上的Windows防火牆狀態?

我已經使用WMI調用進行了調查,但是Root / SecurityCenter2僅保存了第三方防火牆信息,並且我一直無法找到Windows防火牆信息。

似乎搜索注冊表可能是下一個選擇,但是在我走這條路之前,我想看看是否還有其他人有其他想法/建議或代碼示例?

我所做的是使用PSexec來執行防火牆的命令:

Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.FileName = path; //the path of PsExec.exe
        p.StartInfo.Arguments = @"\\" + ip + " netsh advfirewall show domain state "; //you can change domain for allprofile in order to look for all profile firewall information
        p.StartInfo.RedirectStandardOutput = true;
        p.Start();
        string output = p.StandardOutput.ReadToEnd();
        Console.WriteLine(output)
        if (output.Contains("ON"))
        {
           "Domain Firewall enabled";
        }else{
           "Domain Firewall disabled";
        }

PsExec: https ://technet.microsoft.com/zh-cn/sysinternals/bb897553.aspx只需獲取PsExec.exe

string path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\Resources\\PsExec.exe";
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.FileName = path;
        p.StartInfo.Arguments = @"\\" + ip + " netsh advfirewall show domain state ";
        p.StartInfo.RedirectStandardOutput = true;
        p.Start();
        string output = p.StandardOutput.ReadToEnd();
        if (output.Contains("ON"))
        {
            object[] rowResult = { "0", "Server Info", "Domain Firewall enabled, it should be disabled." };
            resultList.Add(rowResult);
        }
        else
        {
            object[] rowResult = { "1", "Server Info", "Domain Firewall disabled." };
            resultList.Add(rowResult);
        }
        return resultList;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM