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;
            }

  • 相关阅读:
    JVM 内存布局
    线程池总结
    Redis持久化
    Java编程基础
    toString()、String.valueOf、(String)强转
    4 种主流的 API 架构风格对比
    kubernetes 节点设置不可调度
    Linux下如何查看哪些进程占用的CPU内存资源最多
    Linux openssl1.0.2k升级openssl1.1.1e版本教程
    对一些权限题密码的说明
  • 原文地址:https://www.cnblogs.com/jinhaoObject/p/4844477.html
Copyright © 2011-2022 走看看