zoukankan      html  css  js  c++  java
  • 获取客户端ip

    private string GetIp()
            {
                string ip = "";
                if (Context.Request.ServerVariables["HTTP_VIA"] != null)// 服务器, using proxy
                {
                    ip = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                if (ip == "" || ip == null)//如果没有使用代理服务器或者得不到客户端的ip  not using proxy or can't get the Client IP
                {                            //得到服务端的地址    

                    ip = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.


                    if (ip == "" || ip == null)//如果没有使用代理服务器或者得不到客户端的ip  not using proxy or can't get the Client IP
                    {
                        string strHostName = System.Net.Dns.GetHostName();

                        string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
                    }

                    if (ip == "" || ip == null)
                    {
                        ip = HttpContext.Current.Request.UserHostAddress;
                    }

                }
                return ip;
            }

  • 相关阅读:
    Oracle中快速查找锁与锁等待
    Oracle查看、修改连接数
    内置数据类型
    代码片段一
    设计模式学习四:依赖倒置原则
    队列
    设计模式学习六:代理模式
    linux 自学系列:一直kill掉多个进程
    设计模式学习五:装饰器模式
    通过__metaclass__为类动态增加方法实例
  • 原文地址:https://www.cnblogs.com/jinhaoObject/p/4844477.html
Copyright © 2011-2022 走看看