zoukankan      html  css  js  c++  java
  • asp.net 获取客服端的Ip地址

    System.Web.HttpContext.Current.Request.ServerVariables获取

    1.没有使用代理服务器的情况:

          REMOTE_ADDR = 用户的 IP
          HTTP_VIA = 没数值或不显示
          HTTP_X_FORWARDED_FOR = 没数值或不显示

    2使用透明代理服务器的情况:Transparent Proxies

          REMOTE_ADDR = 最后一个代理服务器 IP
          HTTP_VIA = 代理服务器 IP
          HTTP_X_FORWARDED_FOR = 用户的真实 IP

    3使用普通匿名代理服务器的情况:Anonymous Proxies

          REMOTE_ADDR = 最后一个代理服务器 IP
          HTTP_VIA = 代理服务器 IP
          HTTP_X_FORWARDED_FOR = 代理服务器 IP

    4使用欺骗性代理服务器的情况:Distorting Proxies

          REMOTE_ADDR = 代理服务器 IP
          HTTP_VIA = 代理服务器 IP
          HTTP_X_FORWARDED_FOR = 随机的 IP

    HTTP_X_FORWARDED_FOR 是HTTP协议中头的一部分,不影响TCP的通讯。也就是说实际上客户端可以发送任意内容的 HTTP_X_FORWARDED_FOR,以就是伪造IP。最简单的是WEB程序的IP记录,本来是要记录真实IP的,反而被“黑客”欺骗。

    这是获取ip方法

    if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)   
          return System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0];      
        else  
          return System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; 

  • 相关阅读:
    Leetcode 349. Intersection of Two Arrays
    hdu 1016 Prime Ring Problem
    map 树木品种
    油田合并
    函数学习
    Leetcode 103. Binary Tree Zigzag Level Order Traversal
    Leetcode 102. Binary Tree Level Order Traversal
    Leetcode 101. Symmetric Tree
    poj 2524 Ubiquitous Religions(宗教信仰)
    pat 1009. 说反话 (20)
  • 原文地址:https://www.cnblogs.com/linsu/p/2265657.html
Copyright © 2011-2022 走看看