zoukankan      html  css  js  c++  java
  • 常用的工具类4-IP类

    public static class IpHelper
    {
    /// <summary>
    /// 获取Ip
    /// </summary>
    /// <returns></returns>
    public static string GetIp()
    {
    string[] IP_Ary;
    string strIP, strIP_list;
    strIP_list = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (strIP_list != null && strIP_list != "")
    {
    strIP_list = strIP_list.Replace("'", "");
    if (strIP_list.IndexOf(",") >= 0)
    {
    IP_Ary = strIP_list.Split(',');
    strIP = IP_Ary[0];
    }
    else
    {
    strIP = strIP_list;
    }
    }
    else
    {
    strIP = "";
    }
    if (strIP == "")
    {
    strIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    strIP = strIP.Replace("'", "");
    }
    return strIP;
    }

    private static double IpToNum(string ip)
    {
    int s1 = 1;
    int s2 = 256 * s1;
    int s3 = 256 * s2;
    int s4 = 256 * s3;
    string[] IpNs = ip.Trim().Split('.');
    try
    {
    double IpN = Convert.ToDouble(IpNs[0]) * s4 + Convert.ToDouble(IpNs[1]) * s3 + IpNs[2].ToInt() * s2 + IpNs[3].ToInt() * s1;
    return IpN;
    }
    catch (Exception)
    {
    return 0;
    }
    }
    }

  • 相关阅读:
    CSS之关于clearfix--清除浮动
    C#之垃圾回收
    C#缓存处理
    Asp.Net Mvc4 Ajax提交数据成功弹框后跳转页面
    Asp.Net MVC Ajax
    C#和SQL操作Xml
    领域模型
    Sql操作表字段
    水晶报表行之间切换颜色
    触发器-Trigger
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/5605534.html
Copyright © 2011-2022 走看看