MCPcopy
hub / github.com/crowdsecurity/crowdsec / IpToRange

Function IpToRange

pkg/exprhelpers/helpers.go:594–618  ·  view source on GitHub ↗

func IpToRange(ip string, cidr string) string {

(params ...any)

Source from the content-addressed store, hash-verified

592
593// func IpToRange(ip string, cidr string) string {
594func IpToRange(params ...any) (any, error) {
595 ip := params[0].(string)
596 cidr := params[1].(string)
597 cidr = strings.TrimPrefix(cidr, "/")
598
599 mask, err := strconv.Atoi(cidr)
600 if err != nil {
601 log.Errorf("bad cidr '%s': %s", cidr, err)
602 return "", nil
603 }
604
605 addr, err := netip.ParseAddr(ip)
606 if err != nil {
607 log.Errorf("can't parse IP address '%s': %v", ip, err)
608 return "", nil
609 }
610
611 prefix, err := addr.Prefix(mask)
612 if err != nil {
613 log.Errorf("can't create prefix from IP address '%s' and mask '%d': %v", ip, mask, err)
614 return "", nil
615 }
616
617 return prefix.String(), nil
618}
619
620// func TimeNow() string {
621func TimeNow(params ...any) (any, error) {

Callers

nothing calls this directly

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…