TsgcWebSocketFirewall › Methods › BanIP
Manually bans an IP address for the specified duration, adding it to the active ban list so all subsequent connections from that IP are rejected.
procedure BanIP(const aIP: string; aDurationSec: Integer = 0);
| Name | Type | Description |
|---|---|---|
aIP | const string | IPv4 or IPv6 address to ban. The ban applies to the exact address; CIDR ranges must be added via the Blacklist property instead. |
aDurationSec | Integer | Ban duration in seconds. Pass 0 (the default) for a permanent ban that is only cleared by UnbanIP, ClearBans, or BanEscalation rotation. |
Use BanIP to block an IP programmatically from application code (for example, from a custom authentication failure handler or an external intrusion-detection feed). The ban is stored together with the bans produced by BruteForce and ThreatScore, so IsBanned, SaveBansToFile and ClearBans all see it. If BanEscalation.Enabled is True the escalation counter is advanced, so repeated manual bans on the same IP grow in duration according to the configured levels. Calls are thread-safe.
// ban an IP for 10 minutes
sgcWebSocketFirewall1.BanIP('203.0.113.45', 600);
// permanent ban
sgcWebSocketFirewall1.BanIP('198.51.100.7', 0);