C# 显示局域网中的所有IP地址
我必须在列表框中显示局域网的所有IP地址。当我想把它绑起来的时候 //代码C# 显示局域网中的所有IP地址,c#,.net,C#,.net,我必须在列表框中显示局域网的所有IP地址。当我想把它绑起来的时候 //代码 Process netUtility = new Process(); netUtility.StartInfo.FileName = "net.exe"; netUtility.StartInfo.CreateNoWindow = true; netUtility.StartInfo.RedirectStandardOutput = true;
Process netUtility = new Process();
netUtility.StartInfo.FileName = "net.exe";
netUtility.StartInfo.CreateNoWindow = true;
netUtility.StartInfo.RedirectStandardOutput = true;
netUtility.StartInfo.UseShellExecute = false;
netUtility.StartInfo.RedirectStandardError = true;
netUtility.Start();
StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream);
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);
netUtility.StartInfo.Arguments = "view";
我哪里错了?需要在流程中添加一行 //代码
Process netUtility = new Process();
netUtility.StartInfo.FileName = "net.exe";
netUtility.StartInfo.CreateNoWindow = true;
netUtility.StartInfo.RedirectStandardOutput = true;
netUtility.StartInfo.UseShellExecute = false;
netUtility.StartInfo.RedirectStandardError = true;
netUtility.Start();
StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream);
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);
netUtility.StartInfo.Arguments = "view";
现在它工作得很好 您可以简单地使用此方法,使其更加灵活和易于使用/理解: C#代码: 通过此链接:
可能重复,请查看以下链接:[[1]: