0

LAN のすべての IP アドレスを ListBox に表示する必要があります。空をバインドしようとしているとき。

// コード

        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); 

どこが間違っていますか?

4

2 に答える 2

1

この方法を簡単に使用できる場合は、はるかに柔軟で使いやすく、理解しやすいです。

C#コード:このリンクから:マシン上のすべてのIPアドレスを取得

    // Get host name
String strHostName = Dns.GetHostName();

// Find host by name
IPHostEntry iphostentry = Dns.GetHostByName(strHostName);

// Enumerate IP addresses
int nIP = 0;
foreach(IPAddress ipaddress in iphostentry.AddressList)
{
    ....
}
于 2013-03-06T10:15:17.770 に答える
0

プロセスに行を追加する必要があります。

//コード

  netUtility.StartInfo.Arguments = "view";

今では正常に動作します!!!

于 2013-03-06T10:14:32.400 に答える