shadow1ng/fscan · error

parse target failed: %w

Error message

parse target failed: %w

What it means

discoverTargets first loads host exclusions and then parses the raw host input into a host list via parsers.ParseIP. If loadHostExcludes fails, the target-parsing stage is aborted and the error is wrapped with the i18n key parse_target_failed ("parse target failed: %w").

Source

Thrown at core/service_scanner.go:367

	}

	if len(servicePlugins) > 0 {
		common.LogInfo(i18n.Tr("service_plugin_info", strings.Join(servicePlugins, ", ")))
	}
}

// =============================================================================
// 端口发现功能(从 PortDiscoveryService 合并)
// =============================================================================

// discoverTargets 发现目标主机和端口
func (s *ServiceScanStrategy) discoverTargets(ctx context.Context, hostInput string, baseInfo common.HostInfo, session *common.ScanSession) ([]common.HostInfo, error) {
	config := session.Config
	state := session.State
	// 标准流程:解析目标主机
	excludes, err := loadHostExcludes(session.Params)
	if err != nil {
		return nil, fmt.Errorf("%s: %w", i18n.GetText("parse_target_failed"), err)
	}
	hosts, err := parsers.ParseIP(hostInput, session.Params.HostsFile, excludes...)
	if err != nil {
		return nil, fmt.Errorf("%s: %w", i18n.GetText("parse_target_failed"), err)
	}

	var targetInfos []common.HostInfo

	// 主机存活性检测和端口扫描
	if len(hosts) > 0 || len(state.GetHostPorts()) > 0 {
		// 主机存活检测
		if s.shouldPerformLivenessCheck(hosts, config) {
			hosts = CheckLive(ctx, hosts, false, session)
			session.LogInfo(i18n.Tr("alive_hosts_count_info", len(hosts)))
		}

		// 端口扫描
		alivePorts := s.discoverAlivePorts(ctx, hosts, session)

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Read the wrapped inner error (%w) to see the exact loadHostExcludes failure.
  2. Fix the exclude argument: each entry must be a valid IP, CIDR, or range.
  3. If using an exclude file, verify every line parses as an IP/CIDR and the file path is correct.
  4. Test the excludes with parsers or a small script before rerunning the full scan.

Example fix

// before
-exclude 192.168.1.0/33
// after
-exclude 192.168.1.0/24
Defensive patterns

Strategy: validation

Validate before calling

for _, e := range strings.Split(excludes, ",") {
    if net.ParseIP(strings.TrimSpace(e)) == nil {
        if _, _, err := net.ParseCIDR(strings.TrimSpace(e)); err != nil {
            return fmt.Errorf("invalid exclude %q", e)
        }
    }
}

Try / catch

targets, err := strategy.PrepareTargets(ctx, params)
if err != nil && strings.Contains(err.Error(), "parse target failed") {
    return fmt.Errorf("fix -exclude syntax: %w", err)
}

Prevention

When it happens

Trigger: Calling PrepareTargets with session.Params whose exclude specification (loaded by loadHostExcludes) is malformed — e.g. invalid exclude IP/CIDR syntax in the -exclude flag or exclude file content.

Common situations: CLI -exclude values with typos (bad CIDR, stray characters), an exclusion file with unparseable lines, or params passed programmatically with invalid exclude data.

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