请教一下~

解决方案 »

  1.   


                    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, TcpPort);
      

  2.   

    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, TcpPort);
    The name 'TcpPort' does not exist in the current context报错
      

  3.   

    string str1=System.Net.Dns.GetHostName;   
    System.Net.IpHostEntry   hostinfo=System.Net.Dns.GetHostByName(str1);   
    System.Net.IpAddress   add1=hostinfo.AddressList[0];   
      

  4.   

    刚才发错了.你试试这个.
                string myIP, myMac;
                System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
                if (addressList.Length > 1)
                {
                    myIP = addressList[0].ToString();
                    myMac = addressList[1].ToString();
                }
                else
                {
                    myIP = addressList[0].ToString();
                }
                Console.WriteLine(myIP);
                Console.ReadKey();
    要引用system.net   
      

  5.   

    string myIP;
                IPAddress[] ipList = Dns.GetHostAddresses(Dns.GetHostName());
                myIP = ipList[0].ToString();
                Console.WriteLine(myIP);
                Console.ReadKey();
      

  6.   

    获得客户端Socket
    然后:
    Socket.RemoteEndPoint
      

  7.   

      public string GetIp()
            {
                System.Net.WebClient client = new System.Net.WebClient();
                client.Encoding = System.Text.Encoding.Default;
                string reply = client.DownloadString("http://www.ip138.com/ip2city.asp");
                int start = reply.IndexOf("[");
                int end = reply.IndexOf("]");
                return reply.Substring((start + 1), (end - start - 1));
            } 
      

  8.   

    万一http://www.ip138.com/ip2city.asp这个地址失效了~~不就没有用了~