shadow1ng/fscan · error

parser_invalid_ip_range_fmt

Error message

parser_invalid_ip_range_fmt

What it means

parseIPRangeString splits the range string on '-'. If the split does not yield exactly two parts, the string is not a start-end range and the function returns 'parser_invalid_ip_range_fmt' formatted with the input. This is a structural check before any IP parsing.

Source

Thrown at common/parsers/parsers.go:344

// looksLikeIPRange 检查字符串是否像IP范围格式
// 如 192.168.1.1-100 或 192.168.1.1-192.168.1.100
// 而不是像 111-555.sss.com 这种域名
func looksLikeIPRange(s string) bool {
	idx := strings.Index(s, "-")
	if idx == -1 {
		return false
	}
	// 检查 - 前面的部分是否是有效IP
	startPart := s[:idx]
	return net.ParseIP(startPart) != nil
}

// parseIPRangeString 解析IP范围字符串
func parseIPRangeString(rangeStr string) ([]string, error) {
	parts := strings.Split(rangeStr, "-")
	if len(parts) != 2 {
		return nil, fmt.Errorf("%s", i18n.Tr("parser_invalid_ip_range_fmt", rangeStr))
	}

	startIPStr := strings.TrimSpace(parts[0])
	endIPStr := strings.TrimSpace(parts[1])

	startIP := net.ParseIP(startIPStr)
	if startIP == nil {
		return nil, fmt.Errorf("%s", i18n.Tr("parser_invalid_start_ip", startIPStr))
	}

	// 处理简写格式 (如: 192.168.1.1-100)
	if len(endIPStr) < 4 || !strings.Contains(endIPStr, ".") {
		return parseIPShortRange(startIPStr, endIPStr)
	}

	// 处理完整格式 (如: 192.168.1.1-192.168.1.100)
	endIP := net.ParseIP(endIPStr)
	if endIP == nil {

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Provide exactly one '-' separating start and end: 192.168.1.1-192.168.1.100
  2. Remove extra hyphens or double dashes from the input
  3. Pre-check strings.Count(s,"-") == 1 before calling ParseIP

Example fix

// before
ParseIP("192.168.1.1-100-200", "")
// after
ParseIP("192.168.1.1-200", "")
Defensive patterns

Strategy: validation

Validate before calling

func isTwoPartRange(s string) bool {
	return strings.Count(s, "-") == 1 && len(strings.Split(s, "-")) == 2
}

Try / catch

if !isTwoPartRange(rangeStr) {
	return fmt.Errorf("range %q must be start-end", rangeStr)
}
_, err := parsers.ParseIP(rangeStr, "")

Prevention

When it happens

Trigger: parseIPRangeString called (via parseHostString from ParseIP, e.g. -h '192.168.1.1-100-200' or 'a-b-c') with a string containing more than one '-' or none in the range branch, i.e. len(strings.Split(rangeStr,"-")) != 2.

Common situations: Typing extra hyphens in the range, pasting strings like '10.0.0.1--10.0.0.5', or range tokens that slipped past looksLikeIPRange with multiple dashes.

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/d4d254f7a21ec2b6. Report an issue: GitHub.