• 常用的工具类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;
    }
    }
    }

  • 相关阅读:
    辞职后的第二个星期
    最近似乎应该休眠了.
    文件.二进制转换
    AVL树
    ajax 的同步和异步
    在SQL Server实现最短路径的搜索
    网页嵌套com例子
    Vs2005 dll 设置def导出函数
    [转]ATL开发一个ActiveX
    Atl COM发布与优化
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/5605534.html
Copyright © 2020-2023  润新知