我正在开发一个应用程序,它可以在给定的网络范围内扫描计算机。从找到的客户端中,我需要获取IP、主机名、Mac地址、操作系统信息等。
现在,除了操作系统版本之外,我已经拥有了上面的所有内容。有谁知道我是如何做到这一点的吗?
我被卡住了。
先谢谢你,克里斯多夫
发布于 2012-03-01 19:41:28
使用WMI,添加对- System.Management dll的引用并提供命名空间,使用以下代码和适当的参数-
ManagementScope scope = new ManagementScope();
try
{
ConnectionOptions conOptions = new ConnectionOptions();
options.Username = "<Provide username>";
options.Password = "<Provide password>";
options.EnablePrivileges = true;
options.Authority = "ntlmdomain:<domianname>";
scope = new ManagementScope(@"\\<IP address/machine name>\root\CIMV2", options);
scope.Connect();
SelectQuery query = new SelectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
using (ManagementObjectCollection queryCollection = searcher.Get())
{
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine(string.Format("Computer Name : {0}", m["csname"]));
Console.WriteLine(string.Format("Windows Directory : {0}", m["WindowsDirectory"]));
Console.WriteLine(string.Format("Operating System: {0}", m["Caption"]));
Console.WriteLine(string.Format("Version: {0}", m["Version"]);
Console.WriteLine(string.Format("Manufacturer : {0}", m["Manufacturer"]));
}
}
}
catch (Exception ex)
{
}您必须有访问权限才能窃取此信息,否则您将获得访问权限例外。
发布于 2012-03-01 19:42:00
您可以使用System.Diagnostics中的Process类运行Nmap并解析结果:
var process = new Process()
{
StartInfo = new ProcessStartInfo()
{
FileName = "cmd.exe",
Arguments = "/c nmap -O -v targethost",
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true
}
};
process.Start();
while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();
// here you can parse to obtain the operating system
}在C#中创建自己的操作系统检测器会很困难,但是如果您对它的工作原理感兴趣,可以在Nmap章节中找到它:Chapter 8. Remote OS Detection
https://stackoverflow.com/questions/9514147
复制相似问题