得到客户端的IP地址

来源:互联网 发布:windows platform sdk 编辑:程序博客网 时间:2024/05/04 14:18

  accSock=sock.Accept();//用于接收客户端的连接请求,返回套接字对象  
  if(accSock.Connected)  
  {  
  IPAddress   ipAddress=IPAddress.Parse(((IPEndPoint)accSock.RemoteEndPoint).Address.ToString());  
  IPAddress   Port=IPAddress.Parse(((IPEndPoint)accSock.RemoteEndPoint).Port.ToString());  
  //获取客户端的IP地址  

 

string GetIp()
        {       
         //可以透过代理服务器
         string userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
         if (userIP == null || userIP == "")
         {
          //没有代理服务器,如果有代理服务器获取的是代理服务器的IP
          userIP = Request.ServerVariables["REMOTE_ADDR"];
         }
         return userIP;
        }

原创粉丝点击