使用C#获取远程机器详细信息 [英] Get remote machie details using c#
问题描述
我正在使用c#和wmi检索机器详细信息.我使用以下代码检索信息:
Hi , i am retrieving machine details using c# and wmi . i using following code to retrieve information:
ManagementScope scope =new ManagementScope(@"\\"+strIPAddress+@"\root\cimv2");
SelectQuery query = new SelectQuery();
query.QueryString = "select * from Win32_OperatingSystem";
ManagementObjectSearcher searcher =new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
//////////////////////////////////
}
对于Windows操作系统,它工作正常.但不适用于linux,Citrix服务器,
我也尝试过此代码:
it is working fine for windows operating system. but it does not works for linux , Citrix server,
i have also tried this code :
string strURL="http://www.google.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
try
{
HttpWebResponse response =(HttpWebResponse) request.GetResponse();
string strServer= response.Server;
}
catch (WebException wex)
{
// Safe cast to HttpWebResponse using 'as', will return null if unsuccessful
var httpWebResponse = wex.Response as HttpWebResponse;
if (httpWebResponse != null)
{
var httpStatusCode = httpWebResponse.StatusCode;
// HttpStatusCode is an enum, cast it to int for its actual value
var httpStatusCodeInt = (int)httpWebResponse.StatusCode;
}
}
但它没有给我远程服务器的操作系统名称,而是给了我IIS的名称.
当我通过互联网搜索时,发现了以下网站:
http://uptime.netcraft.com/ [ ^ ]
任何人都可以检索信息的地方.谁能说出它是如何工作的,或者我们如何使用c#来获取这些细节.
谢谢,
Arshad
but it does not gives me the remote server os name rather it gives me IIS name.
when i searched over internet, i found the following site:
http://uptime.netcraft.com/[^]
where anyone can retrieve information. can anyone tell how is it works or how we can fetch these details using c#.
Thanks,
Arshad
推荐答案
WMI是Windows专有技术,因此您不能将其与Linux等一起使用.
请尝试以下文章:使用.NET的Web服务器信息 [ ^ ]
WMI is a windows specific technology so you cannot use it with Linux etc.
Try the following article : Web Server Information using .NET[^]
这篇关于使用C#获取远程机器详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!