QMS.Common/IPHelper.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.IO;
using System.Text;
using System.Web;

namespace QMS.Common
{
    public class IPHelper
    {
        public static string GetIpCity(string ip)
        {
            IPHelper.EnableFileWatch = true;
            IPHelper.Load(HttpContext.Current.Server.MapPath("/App_Data/17monipdb.dat"));
            if (ip.IsIP())
            {
                return string.Join("", IPHelper.Find(ip));
            }
            else
            {
                return "未知";
            }
        }

        public static bool EnableFileWatch = false;
        private static int offset;
        private static uint[] index = new uint[256];
        private static byte[] dataBuffer;
        private static byte[] indexBuffer;
        private static long lastModifyTime = 0L;
        private static string ipFile;
        private static readonly object @lock = new object();

        public static void Load(string filename)
        {
            ipFile = new FileInfo(filename).FullName;
            Load();
            if (EnableFileWatch)
            {
                Watch();
            }
        }

        public static string[] Find(string ip)
        {
            lock (@lock)
            {
                var ips = ip.Split('.');
                if (ips.Length == 4)
                {
                    var ip_prefix_value = int.Parse(ips[0]);
                    long ip2long_value = BytesToLong(byte.Parse(ips[0]), byte.Parse(ips[1]), byte.Parse(ips[2]),
                        byte.Parse(ips[3]));
                    var start = index[ip_prefix_value];
                    var max_comp_len = offset - 1028;
                    long index_offset = -1;
                    var index_length = -1;
                    byte b = 0;
                    for (start = start * 8 + 1024; start < max_comp_len; start += 8)
                    {
                        if (
后面还有 75 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。