急!在c#中如何获取客户端的ip地址,是广域网的不是局域网的
addr = new System.Net.IPAddress ( Dns.GetHostByName ( Dns.GetHostName ( ) ) .AddressList [1].Address ) ;这种方式获取不到啊

解决方案 »

  1.   


    VB.NET 的
    http://www.cnblogs.com/helloworld84/archive/2005/08/18/218104.html
    通过外部网站返回得到内网外部IP 
      

  2.   

    textBox1.Text = Dns.GetHostByName("www.163.com").AddressList[0].ToString();
    可以的,已经测试过了,试试看。
    你把自己的代码里的addresslist[1],改为addresslist[0]才对。
      

  3.   

    只有穿越NAT之后,才能得到一个映射端口,而非IP,在一个局域网内接到公网的对外都是一个IP,只是端口不同而已(路由分配)
      

  4.   

    String Ip = Request.UserHostAddress.ToString().Trim();就是这个了:)
      

  5.   

    穿过代理服务器取远程用户真实IP地址:  
       if(Request.ServerVariables["HTTP_VIA"]!=null){  
          string  user_IP=Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();  
         }else{  
          string  user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();  
        }
      

  6.   

    private void button3_Click(object sender, System.EventArgs e)
    {
    IPHostEntry host = new IPHostEntry();
    host = Dns.Resolve(this.textBox3.Text);
    for(int i=0; i<host.AddressList.Length;i++)
    {
    this.richTextBox1.AppendText(this.textBox3.Text+ " 的 ip 地址 -->"+host.AddressList[i].ToString()+"\r");
    }
    }
      

  7.   

    this.textBox3.Text 的内容是域名,如:www.sina.com