shadow1ng/fscan · error

parser_invalid_ip_fmt

Error message

parser_invalid_ip_fmt

What it means

parseIPShortRange splits the start IP string on '.' and requires exactly 4 octets. If the start portion is not a dotted-quad (or was not caught earlier), this error is returned with the bad string. It guards the subsequent prefix/octet arithmetic.

Source

Thrown at common/parsers/parsers.go:378

	// 处理完整格式 (如: 192.168.1.1-192.168.1.100)
	endIP := net.ParseIP(endIPStr)
	if endIP == nil {
		return nil, fmt.Errorf("%s", i18n.Tr("parser_invalid_end_ip", endIPStr))
	}

	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) {

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Provide the start IP as a full dotted quad, e.g. '192.168.1.10-50'.
  2. Validate the start portion has exactly 4 dot-separated numeric octets before calling.
  3. Use a hostname resolution step first if the input may be a name rather than an IP.

Example fix

// before
ParseIPRangeString("192.168.1-50")
// after
ParseIPRangeString("192.168.1.1-50")
Defensive patterns

Strategy: validation

Validate before calling

func validStartIP(startPart string) bool {
    parts := strings.Split(startPart, ".")
    if len(parts) != 4 { return false }
    for _, p := range parts {
        n, err := strconv.Atoi(p)
        if err != nil || n < 0 || n > 255 { return false }
    }
    return true
}

Try / catch

ips, err := parseIPRangeString(rangeStr)
if err != nil {
    return fmt.Errorf("bad range start %q: %w", rangeStr, err)
}

Prevention

When it happens

Trigger: Calling parseIPRangeString with a short-form range whose start part is not a valid dotted-quad, e.g. '192.168.1-50', '192.168.1.1.1-20', or a hostname like 'example.com-10'.

Common situations: Users writing hostname ranges or abbreviated IPs ('192.168-50') in scan target lists; IPv6 addresses passed to an IPv4-only parser; extra/missing dots from typos.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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