WmptWap/App_LocalResources/ANTDDOS.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Timers;
/// <summary>
///asp.net 防止ddos攻击
/// </summary>
public class ANTDDOS : IHttpModule
{
void IHttpModule.Dispose() { }
void IHttpModule.Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
private static Dictionary<string, short> _IpAdresses = new Dictionary<string, short>();
private static Stack<string> _Banned = new Stack<string>();
private static Timer _Timer = CreateTimer();
private static Timer _BannedTimer = CreateBanningTimer();
private const int BANNED_REQUESTS = 4; //规定时间内访问的最大次数
private const int REDUCTION_INTERVAL = 120000; // 1 秒(检查访问次数的时间段)
private const int RELEASE_INTERVAL = 24*60 * 60 * 1000; // 5 分钟(清除一个禁止IP的时间段)
private void context_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.AbsolutePath.ToLower().IndexOf("sendgmscode.aspx") > 0)
{
string ip = HttpContext.Current.Request.UserHostAddress;
if (_Banned.Contains(ip))
{
HttpContext.Current.Response.StatusCode = 403;
HttpContext.Current.Response.End();
}
CheckIpAddress(ip);
}
}
/// <summary>
/// 检查访问IP
/// </summary>
private static void CheckIpAddress(string ip)
{
if (!_IpAdresses.ContainsKey(ip)) //如果没有当前访问IP的记录就将访问次数设为1
{
_IpAdresses[ip] = 1;
}
else if (_IpAdresses[ip] == BANNED_REQUESTS) //如果当前IP访问次数等于规定时间段的最大访问次数就拉于“黑名单”
{
_Banned.Push(ip);
_IpAdresses.Remove(ip);
}
else //正常访问就加次数 1
{
_IpAdresses[ip]++;
后面还有 55 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
