shadow1ng/fscan · error

parser_parse_host_failed: %w

Error message

parser_parse_host_failed: %w

What it means

ParseIP parses the comma-separated host argument (IPs, CIDRs, ranges, shorthands like '192') via parseHostString. If that returns an error, ParseIP wraps it with 'parser_parse_host_failed', meaning one of the host expressions in the -h argument could not be parsed.

Source

Thrown at common/parsers/parsers.go:56

	if filename != "" {
		fileHosts, err := ReadLinesFromFile(filename)
		if err != nil {
			return nil, fmt.Errorf(i18n.GetText("parser_read_hosts_failed")+": %w", err)
		}
		for _, h := range fileHosts {
			parsed, err := parseHostString(h)
			if err != nil {
				continue // 跳过无效行
			}
			hosts = append(hosts, parsed...)
		}
	}

	// 解析主机参数
	if host != "" {
		hostList, err := parseHostString(host)
		if err != nil {
			return nil, fmt.Errorf(i18n.GetText("parser_parse_host_failed")+": %w", err)
		}
		hosts = append(hosts, hostList...)
	}

	// 处理排除主机
	if len(nohosts) > 0 {
		matcher := newHostMatcher()
		hasExclude := false
		for _, exclude := range nohosts {
			if strings.TrimSpace(exclude) == "" {
				continue
			}
			hasExclude = true
			if err := matcher.add(exclude); err != nil {
				return nil, fmt.Errorf(i18n.GetText("parser_parse_exclude_failed")+": %w", err)
			}
		}
		if hasExclude {

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Inspect the wrapped inner error (%w) to find which expression failed
  2. Fix the offending CIDR/range syntax (e.g. /0-/32 mask, start<=end)
  3. Validate the host string before calling ParseIP (see validationCode)
  4. Split the comma list and parse each target individually to isolate the bad one

Example fix

// before
ParseIP("192.168.1.0/33", "")
// after
ParseIP("192.168.1.0/24", "")
Defensive patterns

Strategy: try-catch

Validate before calling

for _, h := range strings.Split(host, ",") {
	h = strings.TrimSpace(h)
	if strings.Contains(h, "/") {
		if _, _, err := net.ParseCIDR(h); err != nil { return fmt.Errorf("bad CIDR %q", h) }
	}
}

Try / catch

hosts, err := parsers.ParseIP(host, file)
if err != nil {
	if strings.Contains(err.Error(), "parser_parse_host_failed") {
		log.Fatalf("invalid -h value %q: %v", host, err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling ParseIP with host containing a malformed CIDR (e.g. '10.0.0.0/33') or malformed IP range (e.g. '192.168.1.5-1.2'), which makes the inner parseIPCIDR/parseIPRangeString fail and bubbles up wrapped.

Common situations: Hand-written target lists with typos (bad netmask, reversed range like 192.168.1.100-192.168.1.10), or leftover shell characters in the -h argument.

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