本文介绍了如何使所有计算机列表连接到网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中获取所有连接到网络的计算机的IP地址列表.

how to get the all computers IP address list connected to network in C#

推荐答案


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.



这篇关于如何使所有计算机列表连接到网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 17:39