http://expert.csdn.net/Expert/topic/2930/2930652.xml?temp=.3042871
http://expert.csdn.net/Expert/topic/2934/2934264.xml?temp=.2464868

解决方案 »

  1.   

    试试[C#] 
    try 
    {
       IPAddress hostIPAddress = IPAddress.Parse(IpAddressString);
       IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
       // Get the IP address list that resolves to the host names contained in 
       // the Alias property.
       IPAddress[] address = hostInfo.AddressList;
       // Get the alias names of the addresses in the IP address list.
       String[] alias = hostInfo.Aliases;   Console.WriteLine("Host name : " + hostInfo.HostName);
       Console.WriteLine("\nAliases :");
       for(int index=0; index < alias.Length; index++) {
         Console.WriteLine(alias[index]);
       } 
       Console.WriteLine("\nIP address list : ");
       for(int index=0; index < address.Length; index++) {
          Console.WriteLine(address[index]);
       }
    }
    catch(SocketException e) 
    {
         Console.WriteLine("SocketException caught!!!");
       Console.WriteLine("Source : " + e.Source);
       Console.WriteLine("Message : " + e.Message);
    }
    catch(FormatException e)
    {
         Console.WriteLine("FormatException caught!!!");
       Console.WriteLine("Source : " + e.Source);
       Console.WriteLine("Message : " + e.Message);
    }
    catch(ArgumentNullException e)
    {
         Console.WriteLine("ArgumentNullException caught!!!");
       Console.WriteLine("Source : " + e.Source);
       Console.WriteLine("Message : " + e.Message);
    }
    catch(Exception e)
    {
        Console.WriteLine("Exception caught!!!");
        Console.WriteLine("Source : " + e.Source);
        Console.WriteLine("Message : " + e.Message);
    }
      

  2.   

    如何得到我本地机器的所有IP? 
    作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年6月15日 8点56分15秒 
    --------------------------------------------------------------------------------
     
    [C#]  
         string s ="";  
         System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; 
          for (int i = 0; i < addressList.Length; i ++) 
          { 
               s += addressList[i].ToString() + "\n";  
         } 
          textBox1.Text = s; 
     
    [VB.NET] 
     
         Dim s As String = ""  
         Dim addressList As System.Net.IPAddress() = Dns.GetHostByName(Dns.GetHostName()).AddressList 
     
         Dim i As Integer  
         For i = 0 To addressList.Length - 1  
              s += addressList(i).ToString() + ControlChars.Lf  
         Next i 
         textBox1.Text = s  
      

  3.   

    请问楼上的师傅:
      IPAddress 是在那个命名空间中?
    因为,我调试时提示“不能识别的类型”
      

  4.   

    请问  athossmth(athos)  :
      Dns 是在那个命名空间中?
      

  5.   

    using System.Net;
    using System.Net.Sockets;
      

  6.   

    经过调试, athossmth(athos) 
    的办法运行成功。而且代码比较
    精炼。
    最后请问 athossmth(athos)
    ==============================================
    addressList(i).ToString() 就是本机的本地IP地址;
    ControlChars.Lf           就是本机上网的IP地址;
    ==============================================
    对吗?
      

  7.   

    我招,我不知道。我是抄孟子的。孟子的网站:http://dotnet.aspx.cc,祝你好运。