{"record":{"id":"b631c009dd43d671","repo":"shadow1ng/fscan","slug":"parse-target-failed-w","errorCode":null,"errorMessage":"parse target failed: %w","messagePattern":"parse target failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/service_scanner.go","lineNumber":367,"sourceCode":"\t}\n\n\tif len(servicePlugins) > 0 {\n\t\tcommon.LogInfo(i18n.Tr(\"service_plugin_info\", strings.Join(servicePlugins, \", \")))\n\t}\n}\n\n// =============================================================================\n// 端口发现功能（从 PortDiscoveryService 合并）\n// =============================================================================\n\n// discoverTargets 发现目标主机和端口\nfunc (s *ServiceScanStrategy) discoverTargets(ctx context.Context, hostInput string, baseInfo common.HostInfo, session *common.ScanSession) ([]common.HostInfo, error) {\n\tconfig := session.Config\n\tstate := session.State\n\t// 标准流程：解析目标主机\n\texcludes, err := loadHostExcludes(session.Params)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"parse_target_failed\"), err)\n\t}\n\thosts, err := parsers.ParseIP(hostInput, session.Params.HostsFile, excludes...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"parse_target_failed\"), err)\n\t}\n\n\tvar targetInfos []common.HostInfo\n\n\t// 主机存活性检测和端口扫描\n\tif len(hosts) > 0 || len(state.GetHostPorts()) > 0 {\n\t\t// 主机存活检测\n\t\tif s.shouldPerformLivenessCheck(hosts, config) {\n\t\t\thosts = CheckLive(ctx, hosts, false, session)\n\t\t\tsession.LogInfo(i18n.Tr(\"alive_hosts_count_info\", len(hosts)))\n\t\t}\n\n\t\t// 端口扫描\n\t\talivePorts := s.discoverAlivePorts(ctx, hosts, session)","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/core/service_scanner.go#L349-L385","documentation":"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\").","triggerScenarios":"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.","commonSituations":"CLI -exclude values with typos (bad CIDR, stray characters), an exclusion file with unparseable lines, or params passed programmatically with invalid exclude data.","solutions":["Read the wrapped inner error (%w) to see the exact loadHostExcludes failure.","Fix the exclude argument: each entry must be a valid IP, CIDR, or range.","If using an exclude file, verify every line parses as an IP/CIDR and the file path is correct.","Test the excludes with parsers or a small script before rerunning the full scan."],"exampleFix":"// before\n-exclude 192.168.1.0/33\n// after\n-exclude 192.168.1.0/24","handlingStrategy":"validation","validationCode":"for _, e := range strings.Split(excludes, \",\") {\n    if net.ParseIP(strings.TrimSpace(e)) == nil {\n        if _, _, err := net.ParseCIDR(strings.TrimSpace(e)); err != nil {\n            return fmt.Errorf(\"invalid exclude %q\", e)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"targets, err := strategy.PrepareTargets(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"parse target failed\") {\n    return fmt.Errorf(\"fix -exclude syntax: %w\", err)\n}","preventionTips":["Validate exclude IPs/CIDRs with net.ParseIP/ParseCIDR before scanning","Keep exclude files one entry per line, valid IP or CIDR","Trim whitespace and drop empty tokens from exclude input"],"tags":["target-parsing","validation","cidr","scanner"],"backgroundTag":"invalid-argument-format","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}