iptracker

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2025 License: Unlicense Imports: 2 Imported by: 0

Documentation

Overview

Package iptracker provides functionality to track and block IP addresses based on failed authentication attempts.

Index

Constants

View Source
const (
	// BlockDuration is the duration for which an IP will be blocked after
	// exceeding the maximum number of failed attempts.
	BlockDuration = 10 * time.Minute
)

Variables

View Source
var Global = NewIPTracker()

Global instance of IPTracker for use across the application

Functions

This section is empty.

Types

type IPTracker

type IPTracker struct {
	// contains filtered or unexported fields
}

IPTracker tracks failed authentication attempts by IP address and provides functionality to block IPs that exceed a threshold.

func NewIPTracker

func NewIPTracker() *IPTracker

NewIPTracker creates a new IPTracker instance.

func (*IPTracker) GetBlockedUntil

func (t *IPTracker) GetBlockedUntil(ip string) time.Time

GetBlockedUntil returns the time until which the given IP address is blocked. If the IP is not blocked, it returns the zero time.

func (*IPTracker) IsBlocked

func (t *IPTracker) IsBlocked(ip string) bool

IsBlocked checks if the given IP address is currently blocked.

func (*IPTracker) RecordFailedAttempt

func (t *IPTracker) RecordFailedAttempt(ip string) bool

RecordFailedAttempt records a failed authentication attempt for the given IP address. If the number of failed attempts exceeds the threshold, the IP is blocked for the configured duration. Returns true if the IP is now blocked, false otherwise.

func (*IPTracker) Reset

func (t *IPTracker) Reset(ip string)

Reset resets the failed attempts counter for the given IP address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL