owasp-amass/amass · error

%s is not a valid IP address or range

Error message

%s is not a valid IP address or range

What it means

Within ParseIPs.Set, each comma-separated entry is first tried via parseRange; if range-like, amassnet.RangeHosts must yield at least one IP. If the range yields zero hosts — or the entry is otherwise not a single valid IP — the flag returns this per-entry error, keeping the parsed []net.IP free of unusable entries.

Source

Thrown at internal/afmt/parse.go:107

		if i > 0 {
			builder.WriteRune(',')
		}
		builder.WriteString(ipaddr.String())
	}
	return builder.String()
}

// Set implements the flag.Value interface.
func (p *ParseIPs) Set(s string) error {
	if s == "" {
		return fmt.Errorf("IP address parsing failed")
	}

	for _, v := range strings.Split(s, ",") {
		if start, end, ok := parseRange(v); ok {
			ips := amassnet.RangeHosts(start, end)
			if len(ips) == 0 {
				return fmt.Errorf("%s is not a valid IP address or range", v)
			}
			for _, ip := range ips {
				*p = append(*p, ip)
			}
			continue
		} else if ip := net.ParseIP(v); ip != nil {
			*p = append(*p, ip)
			continue
		} else {
			return fmt.Errorf("%s is not a valid IP address or range", v)
		}
	}
	return nil
}

func parseRange(s string) (start net.IP, end net.IP, ok bool) {
	twoIPs := strings.Split(s, "-")
	if len(twoIPs) != 2 {

View on GitHub (pinned to 79299dce87)

Solutions

  1. Validate each entry with net.ParseIP or as start-end range before passing the flag.
  2. Fix reversed ranges so start < end within the same address family.
  3. Replace hostnames with resolved IP addresses; DNS names are not accepted here.

Example fix

// before
-ip "example.com,192.168.1.1"    // example.com is not a valid IP address or range
// after
-ip "93.184.216.34,192.168.1.1"  // use the resolved address
Defensive patterns

Strategy: validation

Validate before calling

func validIPRangeEntry(v string) bool {
	if ip := net.ParseIP(v); ip != nil { return true }
	if i := strings.Index(v, "-"); i > 0 {
		start, end := net.ParseIP(v[:i]), net.ParseIP(v[i+1:])
		if start != nil && end != nil {
			return bytes.Compare(start.To16(), end.To16()) <= 0
		}
	}
	return false
}

Type guard

func isParseableIP(s string) bool { return net.ParseIP(s) != nil }

Prevention

When it happens

Trigger: Passing a range whose start >= end or with mismatched address families (e.g. "10.0.0.5-10.0.0.1", "192.168.1.1-::10") so RangeHosts returns zero IPs, or a token that fails range parsing and net.ParseIP (e.g. "192.168.1.999", "example.com").

Common situations: Reversed ranges after copy-paste, hostnames given where only IPs are accepted, octet typos producing unparseable addresses, IPv4/IPv6 mixing in ranges.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/b5006434d759d1f8. Report an issue: GitHub.