• 获取*IP地址


    public static string GetRealIP()
    {
                string result = String.Empty;
                result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (null == result || result == String.Empty)
                {
                    result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                if (null == result || result == String.Empty)
                {
                    result = HttpContext.Current.Request.UserHostAddress;
                }
                if (null == result || result == String.Empty)
                {
                    return "0.0.0.0";
                }
                return result == "127.0.0.1" ? GetUserIP() : result;
    }

     public static string GetUserIP()
     {
                WebClient client = new WebClient();
                client.Encoding = System.Text.Encoding.Default;
                string response = client.UploadString("http://iframe.ip138.com/ipcity.asp", "");
                Match mc = Regex.Match(response, @"location.href=""(.*)""");
                response = client.UploadString(mc.Groups[1].Value, "");
                int i = response.IndexOf("[") + 1;
                string ip = response.Substring(i, response.IndexOf("]") - i);
                string ips = ip.Replace("]", "").Replace(" ", "");
                return ips;
     }

  • 相关阅读:
    彻底移除mc
    产生N个不重复的随机数字
    画方格线
    运动方式工具类
    物体围绕另一个物体圆形运动
    检测碰撞工具类(两个类各有特点 可以结合使用)
    hdu 1069 Monkey and Banana (DP)
    hdu 1158 Employment Planning (DP)
    hdu 1003 Max Sum (DP)
    hdu 2550百步穿杨 (DP)
  • 原文地址:https://www.cnblogs.com/jdk123456/p/3520659.html
Copyright © 2020-2023  润新知