Documentation
¶
Overview ¶
Package netutil provides network utility functions for NFTBan Centralizes IP address handling, whitelist checking, and CIDR operations
Index ¶
- func GetClientIP(r *http.Request) string
- func GetIPFamily(ipStr string) string
- func IPContainedInCIDR(ipStr, cidr string) bool
- func IsCIDR(s string) bool
- func IsIPWhitelisted(clientIP string, whitelistFile string) (bool, error)
- func IsIPv4(ipStr string) bool
- func IsIPv6(ipStr string) bool
- func IsPrivateIP(ipStr string) bool
- func IsPublicIP(ipStr string) bool
- func IsValidIP(ipStr string) bool
- func NormalizeIP(ipStr string) string
- func ParseCIDR(cidr string) (net.IP, *net.IPNet, error)
- func ParseIP(ipStr string) net.IP
- func ValidateAndNormalizeIP(ipStr string) (string, bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClientIP ¶
GetClientIP extracts the real client IP address from an HTTP request Checks headers in order: X-Forwarded-For, X-Real-IP, RemoteAddr
func GetIPFamily ¶
GetIPFamily returns "ipv4" or "ipv6" based on the IP address
func IPContainedInCIDR ¶
IPContainedInCIDR checks if an IP is contained within a CIDR range
func IsIPWhitelisted ¶
IsIPWhitelisted checks if an IP is in a whitelist file Returns (true, nil) if IP is whitelisted Returns (false, nil) if IP is not whitelisted or file doesn't exist Returns (false, error) on file read errors
func IsPrivateIP ¶
IsPrivateIP checks if an IP is a private/local address
func IsPublicIP ¶
IsPublicIP checks if an IP is a public/routable address
func NormalizeIP ¶
NormalizeIP returns a normalized string representation of an IP Useful for consistent map keys and comparisons
Types ¶
This section is empty.