2011-03-19 28 views
0

可能重複:
get ip address of all pc on my pc which is connected in lan in c#獲得所有連接的PC的IP地址

這是我code.I只給我的計算機的IP地址,但我想的IP地址所有在lan.also連接的計算機,我給這個代碼的故障排除錯誤。請給我解決方案,更改代碼。

static void Main(string[] args) 
{ 
    System.Diagnostics.Process p = new System.Diagnostics.Process(); 
    p.StartInfo.FileName = "cmd "; 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.Arguments = "/C net view"; 
    p.StartInfo.RedirectStandardOutput = true; 
    p.Start(); 
    String output = p.StandardOutput.ReadToEnd(); 
    char[] delimiters = new char[] { '\n' }; 
    String strHostName = string.Empty; 

    string[] s = output.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); 
    IPHostEntry ipEntry = Dns.GetHostEntry(strHostName); 
    IPAddress[] addr = ipEntry.AddressList; 



    p.WaitForExit(); 
    int z = s.Length - 5; 


    string[] str1 = new string[z]; 
    int i = 0; 
    char[] saperator = { ' '}; 
    for (int j = 3; j < s.Length - 2; j++, i++) 
    { 

     str1[i] = (s[j].ToString()).Split(saperator)[0] ; 
     Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString()); 
    } 
    //Console.WriteLine(output); 

    Console.ReadLine(); 
} 
+0

你能告訴我們什麼不工作?你不能從NET VIEW命令獲得輸出嗎?你無法解析條目嗎? DNS沒有解決?你遇到什麼錯誤,它在哪裏發生? – 2011-03-19 14:35:57

+0

好像我們有一個閉環。這個問題正在被關閉,因爲它是另一個問題的重複,並且*問題已經關閉,因爲它是這個問題的重複。現在又有第三個問題被關閉了,因爲它與這兩個重複。 。 。 – 2011-03-19 14:37:34

回答

0

林不完全是一個專業的,但我認爲你需要什麼是所謂的端口掃描程序,可以實現一個端口掃描器的非常基本的功能集成到你的應用程序和網絡中讀取所有的活IPS

一個解決辦法是: http://www.geekpedia.com/tutorial142_Creating-a-Port-Scanner-with-Csharp.html

他們甚至有可供下載網站上的代碼。還沒有嘗試下載它艱難。 :)