netutil

package
v1.0.30 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package netutil provides network utility functions for NFTBan Centralizes IP address handling, whitelist checking, and CIDR operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClientIP

func GetClientIP(r *http.Request) string

GetClientIP extracts the real client IP address from an HTTP request Checks headers in order: X-Forwarded-For, X-Real-IP, RemoteAddr

func GetIPFamily

func GetIPFamily(ipStr string) string

GetIPFamily returns "ipv4" or "ipv6" based on the IP address

func IPContainedInCIDR

func IPContainedInCIDR(ipStr, cidr string) bool

IPContainedInCIDR checks if an IP is contained within a CIDR range

func IsCIDR

func IsCIDR(s string) bool

IsCIDR checks if a string is a valid CIDR notation

func IsIPWhitelisted

func IsIPWhitelisted(clientIP string, whitelistFile string) (bool, error)

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 IsIPv4

func IsIPv4(ipStr string) bool

IsIPv4 checks if an IP string represents an IPv4 address

func IsIPv6

func IsIPv6(ipStr string) bool

IsIPv6 checks if an IP string represents an IPv6 address

func IsPrivateIP

func IsPrivateIP(ipStr string) bool

IsPrivateIP checks if an IP is a private/local address

func IsPublicIP

func IsPublicIP(ipStr string) bool

IsPublicIP checks if an IP is a public/routable address

func IsValidIP

func IsValidIP(ipStr string) bool

IsValidIP checks if a string is a valid IP address (v4 or v6)

func NormalizeIP

func NormalizeIP(ipStr string) string

NormalizeIP returns a normalized string representation of an IP Useful for consistent map keys and comparisons

func ParseCIDR

func ParseCIDR(cidr string) (net.IP, *net.IPNet, error)

ParseCIDR parses a CIDR string and returns the IP and network

func ParseIP

func ParseIP(ipStr string) net.IP

ParseIP parses an IP address string and returns the net.IP Returns nil if the string is not a valid IP

func ValidateAndNormalizeIP

func ValidateAndNormalizeIP(ipStr string) (string, bool, error)

ValidateAndNormalizeIP validates and normalizes an IP or CIDR Returns: (normalized string, isIPv4, error) Used by blacklist/whitelist loaders for consistent IP handling

Types

This section is empty.

Jump to

Keyboard shortcuts

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