如何使所有计算机列表连接到网络
问题描述:
如何在C#中获取所有连接到网络的计算机的IP地址列表.
how to get the all computers IP address list connected to network in C#
答
在CP本身的LAN网络上的许多文章中,这应该满足您的要求.需要:一个收集类,用于列出网络中所有计算机和服务器以及类别信息 [ ^ ]
请使用CP文章存储库,它有很多文章.一个简单的搜索可以为您提供更多所需的信息.
之前曾问过并回答过类似的问题:获取ipp地址通过局域网连接的所有计算机 [ ^ ]
Of many articles on LAN network here at CP itself, this one should meet your needs: A collection class for listing all the computers and servers in your network, with category information[^]
Please use CP articles repository, it has great many articles. A simple search can provide you much more in case you need.
Similar questions asked earlier and answered: get ipp address of all pcs connected via lan [^]
0)我在msdn上找到了此代码,但是如果您在公司/军事网络中,您可能无法获得所需的输出:
0) I found this code on msdn, but if you''re on a corporate/military network, you may not be able to get the desired output:
using System.Diagnostics;
using System.IO;
//Gets the machine names that are connected on LAN
Process netUtility = new Process();
netUtility.StartInfo.FileName = "net.exe";
netUtility.StartInfo.CreateNoWindow = true;
netUtility.StartInfo.Arguments = "view";
netUtility.StartInfo.RedirectStandardOutput = true;
netUtility.StartInfo.UseShellExecute = false;
netUtility.StartInfo.RedirectStandardError = true;
netUtility.Start();
StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);
string line = "";
while ((line = streamReader.ReadLine()) != null)
{
if (line.StartsWith("\\"))
{
listBox1.Items.Add(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper());
}
}
streamReader.Close();
netUtility.WaitForExit(1000);
1)您可以执行ping扫描,但是这将永远持续下去,并且如果在任何一个盒子上都启用了Windows防火墙,则它可能被配置为拒绝ICMP请求,并且您仍然被卡住-再次.
2)在第一个示例中使用net.exe,可以使用nMap.exe. Google的命令行参数.
1) You could do a ping sweep, but that would take forever, and if the Windows firewall is enabled on any of the boxes, it may be configured to refuse ICMP requests, and you''re stuck - again.
2) Insteat of using net.exe in the first example, you could use nMap.exe. Google for the commandline parameters.
如果所有都连接到Windows服务器-LDAP,我们可以获得该信息.希望它能解决.
If all connected to windows server - LDAP, we can get that information. Hope it solves.