Documentation ¶
Overview ¶
Package ipchecking wrapper over net/netip to compare both IP and CIRD.
Example ¶
package main import ( "fmt" "github.com/tomMoulard/fail2ban/pkg/ipchecking" ) func main() { // Parse multiple IPs/CIDRS ips, err := ipchecking.ParseNetIPs([]string{ "127.0.0.1", "10.0.0.0/24", // 10.0.0.1-10.0.0.254 "::1", "2001:db8::/32", }) if err != nil { panic(err) } // Check if an IP is either in the list, or in the list networks fmt.Println(ips.Contains("")) // false (empty string is not an IP) fmt.Println(ips.Contains("127.0.0.1")) // true fmt.Println(ips.Contains("127.0.0.2")) // false fmt.Println(ips.Contains("10.0.0.42")) // true fmt.Println(ips.Contains("::1")) // true fmt.Println(ips.Contains("2001:db8:beba:cafe::1:2")) // true fmt.Println(ips.Contains("64:ff9b::127.0.0.1")) // false }
Output: false true false true true true false
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NetIP ¶
NetIP struct that holds an NetIP IP address, and a IP network. If the network is nil, the NetIP is a single IP.
func ParseNetIP ¶
ParseNetIP Parse a string to extract the netip.
type NetIPs ¶
type NetIPs []NetIP
func ParseNetIPs ¶
ParseNetIPs Parse a slice string to extract the netip. Returns an error on the first IP that failed to parse.
Click to show internal directories.
Click to hide internal directories.