Open AbrarJahin opened 6 years ago
using System; using System.Web; using System.Collections.Generic; using System.Collections.Specialized; using System.Timers;
///
void IHttpModule.Dispose() { // Nothing to 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
private const int BANNED_REQUESTS = 10; private const int REDUCTION_INTERVAL = 1000; // 1 second private const int RELEASE_INTERVAL = 5 60 1000; // 5 minutes
private void context_BeginRequest(object sender, EventArgs e) { string ip = HttpContext.Current.Request.UserHostAddress; if (_Banned.Contains(ip)) { HttpContext.Current.Response.StatusCode = 403; HttpContext.Current.Response.End(); }
CheckIpAddress(ip);
}
///
///
///
///
return timer;
}
///
}
https://madskristensen.net/blog/block-dos-attacks-easily-in-aspnet/