IPAddress[] ipadd;
            string hostname = Dns.GetHostName();
            ipadd=Dns.GetHostAddresses(hostname);
           
            foreach (IPAddress ip in ipadd)
            {
                MessageBox.Show(hostname);
                MessageBox.Show(ip.ToString());
            } 

解决方案 »

  1.   

    可以首先获得本机的IP地址,然后把IP最后一位从0枚举到255,并Ping这些机器但这样的效率较低,一般到多线程其速度才能让人接受,我推荐用net view命令: Process p = new Process();
                p.StartInfo.FileName = "net";
                p.StartInfo.Arguments = "view";
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();
                while (!p.StandardOutput.EndOfStream)
                {
                    string s = p.StandardOutput.ReadLine();
                    if (s.StartsWith(@"\\"))
                    {
                        try
                        {
                            Console.WriteLine(Dns.GetHostByName(s.Substring(2, s.IndexOf(' ') - 1)).AddressList[0].ToString());
                        }
                        catch { }
                    }
                }
      

  2.   

    参考:
    http://www.microsoft.com/china/community/program/originalarticles/TechDoc/DirectoryEntry.mspx
    效果如下图:
      

  3.   

       DirectoryEntry root = new DirectoryEntry("WinNT:"); 
        DirectoryEntries domains = root.Children; 
        domains.SchemaFilter.Add("domain"); 
        foreach (DirectoryEntry domain in domains) { 
      IPHostEntry iphe = null; 
        try { 
            iphe = Dns.GetHostByName(computer.Name); 
          } 
        catch { } 
      }或
    string strIPAddress="192.168.1."; 
                int nStrat = Int32.Parse("1"); 
                int nEnd =Int32.Parse("255"); 
                for(int i=nStrat;i<=nEnd;i++) 
                { 
                    string strScanIPAdd = strIPAddress +i.ToString(); 
                    IPAddress myScanIP = IPAddress.Parse(strScanIPAdd); 
                    try 
                    { 
                        IPHostEntry myScanHost = Dns.GetHostByAddress(myScanIP); 
                        string strHostName =myScanHost.HostName.ToString(); 
                        this.listBox2.Items.Add(strScanIPAdd+"->"+strHostName+"\r"); 
                    } 
                    catch 
                    { 
                        
                    }      
                }   
    http://www.codeproject.com/KB/IP/Network_Computers.aspx
      

  4.   

    不知道这个是不是你想要的http://webservices.ctocio.com.cn/net/269/9202269.shtml