shadow1ng/fscan · error

parser_invalid_ip_range_val

Error message

parser_invalid_ip_range_val

What it means

After validating the end suffix and 4-octet shape, parseIPShortRange converts the last octet of the start IP to an integer. This error fires when that octet is non-numeric or when the start number is greater than the end number, which would produce an empty/degenerate range.

Source

Thrown at common/parsers/parsers.go:384

	return parseIPFullRange(startIP, endIP)
}

// parseIPShortRange 解析短格式IP范围
func parseIPShortRange(startIPStr, endSuffix string) ([]string, error) {
	endNum, err := strconv.Atoi(endSuffix)
	if err != nil || endNum > 255 {
		return nil, fmt.Errorf("%s", i18n.Tr("parser_invalid_ip_end_val", endSuffix))
	}

	ipParts := strings.Split(startIPStr, ".")
	if len(ipParts) != 4 {
		return nil, fmt.Errorf("%s", i18n.Tr("parser_invalid_ip_fmt", startIPStr))
	}

	prefixIP := strings.Join(ipParts[0:3], ".")
	startNum, err := strconv.Atoi(ipParts[3])
	if err != nil || startNum > endNum {
		return nil, fmt.Errorf("%s", i18n.Tr("parser_invalid_ip_range_val", startIPStr, endSuffix))
	}

	var allIP []string
	for i := startNum; i <= endNum; i++ {
		allIP = append(allIP, fmt.Sprintf("%s.%d", prefixIP, i))
	}

	return allIP, nil
}

// parseIPFullRange 解析完整格式的IP范围
func parseIPFullRange(startIP, endIP net.IP) ([]string, error) {
	start4 := startIP.To4()
	end4 := endIP.To4()
	if start4 == nil || end4 == nil {
		return nil, fmt.Errorf("%s", i18n.GetText("parser_ipv4_only"))
	}

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Swap the values so the start octet is <= the end octet, e.g. '192.168.1.10-60'.
  2. Ensure the start IP's last octet is numeric and <= 255.
  3. Pre-validate in code: parse both numbers and check start <= end before invoking.

Example fix

// before
ParseIPRangeString("192.168.1.60-50")
// after
ParseIPRangeString("192.168.1.50-60")
Defensive patterns

Strategy: validation

Validate before calling

func orderedShortRange(r string) bool {
    dash := strings.IndexByte(r, '-')
    if dash < 0 { return false }
    octets := strings.Split(r[:dash], ".")
    if len(octets) != 4 { return false }
    start, err1 := strconv.Atoi(octets[3])
    end, err2 := strconv.Atoi(r[dash+1:])
    return err1 == nil && err2 == nil && start <= end
}

Try / catch

ips, err := parseIPRangeString(rangeStr)
if err != nil {
    return fmt.Errorf("start must be <= end in %q: %w", rangeStr, err)
}

Prevention

When it happens

Trigger: Ranges like '192.168.1.60-50' (start octet > end) or '192.168.1.x-50' (non-numeric start octet).

Common situations: Swapped start/end values when writing target ranges; typos in the final octet; auto-generated ranges where the interval collapsed to nothing.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06). Data as JSON: /api/errors/edc016a430ae956b. Report an issue: GitHub.