2013-03-06 1 views
0

LAN의 모든 IP 주소를 ListBox에 표시해야합니다. 내가 비어있는 것을 묶으려고 할 때.LAN에서 모든 IP 주소 표시

// 코드

내가 틀렸다
 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); 

?

+0

가능한 복제 다음 링크를보고하십시오, [http://stackoverflow.com/questions/965088/get-all-ips-in-the-same-network-as-my-computer][1] [1] : http://stackoverflow.com/questions/965088/get-all-ips-in-the-same-network-as-my-computer –

답변

0

프로세스에 행을 추가해야합니다.

// 코드

netUtility.StartInfo.Arguments = "view"; 

지금 그것을 잘 작동합니다! 당신은 단순히 사용하는 것이 훨씬 더 유연하고 쉽게이 방법을 사용할 수 있습니다

1

이/이해 :

C# 코드 : 를이 링크에서 : Get All IP Addresses on Machine

// 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) 
{ 
    .... 
} 
+0

시도해보십시오. –