/// <summary> /// 设置修改人信息 /// </summary> /// <param name="updateInfo">被赋值的实体</param> /// <param name="updateID">创建人ID</param> /// <param name="updateName">创建人名称</param> public static void SetUpdateInfo(this IUpdateInfo updateInfo, int?updateID = 0, string updateName = "") { updateInfo.UpdateIP = Req.GetIP(); updateInfo.UpdateAt = DateTime.Now; updateInfo.UpdateID = updateID; updateInfo.UpdateName = updateName; }
/// <summary> /// 设置审核人信息 /// </summary> /// <param name="auditInfo">被赋值的实体</param> /// <param name="auditID">创建人ID</param> /// <param name="auditName">创建人名称</param> public static void SetAuditInfo(this IAuditInfo auditInfo, int?auditID = 0, string auditName = "") { auditInfo.AuditIP = Req.GetIP(); auditInfo.AuditAt = DateTime.Now; auditInfo.AuditID = auditID; auditInfo.AuditName = auditName; }
/// <summary> /// 设置创建人信息 /// </summary> /// <param name="createInfo">被赋值的实体</param> /// <param name="createID">创建人ID</param> /// <param name="createName">创建人名称</param> public static void SetCreateInfo(this ICreateInfo createInfo, int?createID = 0, string createName = "") { createInfo.CreateIP = Req.GetIP(); createInfo.CreateAt = DateTime.Now; createInfo.CreateID = createID; createInfo.CreateName = createName; }
/// <summary> /// 执行跳转功能 /// </summary> protected void IPSecurity_AuthorizeRequest(object sender, EventArgs e) { var app = (HttpApplication)sender; var clientIP = Req.GetIP(); var config = WebIPSecurityConfigs.ConfigEntity; //app.Response.Write($"<!--{location.Area}|| {location.Province}|| {location.City}|| {location.Address}-->"); // 循环所有跳转规则 if (config.IPList.Select(ip => IpAdress.IsContains(clientIP, ip)).Any(result => config.IsBlacklistMode == result)) { Jump(app.Context); return; } // 中文地址的方式 if (config.AddressList.Count <= 0) { return; } var location = IpAdress.GetLocation(clientIP); if (config.IsBlacklistMode != config.AddressList.Any(o => location.Area.Contains(o) || location.Province.Contains(o) || location.City.Contains(o) || location.Address.Contains(o))) { return; } Jump(app.Context); }
/// <summary> /// 获取IP地址位置 /// </summary> /// <param name="ip">IP</param> public static string GetAddress(string ip = "") { if (string.IsNullOrWhiteSpace(ip)) { ip = Req.GetIP(); } var loc = GetLocation(ip); return(loc.Area + loc.Address); }
/// <summary> /// 查找指定IP位置 /// </summary> /// <param name="ip"></param> /// <returns></returns> public static Location GetLocation(string ip = "") { if (string.IsNullOrWhiteSpace(ip)) { ip = Req.GetIP(); } if (data == null) { using (var fs = new FileStream(File, FileMode.Open, FileAccess.Read, FileShare.Read)) { data = new byte[fs.Length]; fs.Read(data, 0, data.Length); } var buffer = new byte[8]; Array.Copy(data, 0, buffer, 0, 8); _firstStartIpOffset = ((buffer[0] + (buffer[1] * 0x100)) + ((buffer[2] * 0x100) * 0x100)) + (((buffer[3] * 0x100) * 0x100) * 0x100); _lastStartIpOffset = ((buffer[4] + (buffer[5] * 0x100)) + ((buffer[6] * 0x100) * 0x100)) + (((buffer[7] * 0x100) * 0x100) * 0x100); _ipCount = Convert.ToInt64((((_lastStartIpOffset - _firstStartIpOffset)) / 7.0)); if (_ipCount <= 1L) { throw new ArgumentException("ip FileDataError"); } } if (!regex.Match(ip).Success) { throw new ArgumentException("IP格式错误"); } var location = new Location { IP = ip }; var intIP = IpToInt(ip); if ((intIP >= IpToInt("127.0.0.1") && (intIP <= IpToInt("127.255.255.255")))) { location.Area = "本机/局域网地址"; location.Address = ""; } else { if ((((intIP >= IpToInt("0.0.0.0")) && (intIP <= IpToInt("2.255.255.255"))) || ((intIP >= IpToInt("64.0.0.0")) && (intIP <= IpToInt("126.255.255.255")))) || ((intIP >= IpToInt("58.0.0.0")) && (intIP <= IpToInt("60.255.255.255")))) { location.Area = "网络保留地址"; location.Address = ""; } } var right = _ipCount; var left = 0L; var startIp = 0L; var endIpOff = 0L; var endIp = 0L; var countryFlag = 0; while (left < (right - 1L)) { var middle = (right + left) / 2L; startIp = GetStartIp(middle, out endIpOff); if (intIP == startIp) { left = middle; break; } if (intIP > startIp) { left = middle; } else { right = middle; } } startIp = GetStartIp(left, out endIpOff); endIp = GetEndIp(endIpOff, out countryFlag); if ((startIp <= intIP) && (endIp >= intIP)) { string local; location.Area = GetCountry(endIpOff, countryFlag, out local); location.Address = local; } else { location.Area = "未知"; location.Address = ""; } location.Address = Regex.Replace(location.Address, "CZ88.NET", "", RegexOptions.IgnoreCase); return(location); }
/// <summary> /// 获取IP地址位置 /// </summary> /// <param name="province">返回省份</param> /// <param name="city">返回城市</param> public static string GetAddress(out string province, out string city) { return(GetAddress(Req.GetIP(), out province, out city)); }