string computerName = Dns.GetHostName();//获得本机器名称
        IPAddress ipaddr = (Dns.GetHostAddresses(computerName))[0]; //获得本机器的IPAddress       string aa=ipaddr.ToString();
行的

解决方案 »

  1.   

    试过ipaddr .ToString()返回的是什么?
      

  2.   

    这样:       // 获取本地IP
                string hostName = Dns.GetHostName();
                IPHostEntry entry = Dns.GetHostEntry((hostName));
                foreach (IPAddress ip in entry.AddressList)
                {
                    IP = ip.ToString();
                }