zoukankan      html  css  js  c++  java
  • 获取IP地址

    public static string GetIpAddress()
            {
                string ipAddress = null;
                if (HttpContext.Current != null)
                {
                    ipAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                if (string.IsNullOrWhiteSpace(ipAddress))
                {
                    foreach (var hostAddress in Dns.GetHostAddresses(Dns.GetHostName()))
                    {
                        if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
                        {
                            return hostAddress.ToString();
                        }
                    }
                }
                else
                {
                    return ipAddress;
                }
                return string.Empty;
            }
  • 相关阅读:
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    12.20++对王建民老师的评价+个人期末总结
    12.19
    12.18
    12.17
    12.16
  • 原文地址:https://www.cnblogs.com/flywing/p/6439144.html
Copyright © 2011-2022 走看看