{"record":{"id":"d4d254f7a21ec2b6","repo":"shadow1ng/fscan","slug":"parser-invalid-ip-range-fmt-d4d254","errorCode":null,"errorMessage":"parser_invalid_ip_range_fmt","messagePattern":"parser_invalid_ip_range_fmt","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/parsers/parsers.go","lineNumber":344,"sourceCode":"\n// looksLikeIPRange 检查字符串是否像IP范围格式\n// 如 192.168.1.1-100 或 192.168.1.1-192.168.1.100\n// 而不是像 111-555.sss.com 这种域名\nfunc looksLikeIPRange(s string) bool {\n\tidx := strings.Index(s, \"-\")\n\tif idx == -1 {\n\t\treturn false\n\t}\n\t// 检查 - 前面的部分是否是有效IP\n\tstartPart := s[:idx]\n\treturn net.ParseIP(startPart) != nil\n}\n\n// parseIPRangeString 解析IP范围字符串\nfunc parseIPRangeString(rangeStr string) ([]string, error) {\n\tparts := strings.Split(rangeStr, \"-\")\n\tif len(parts) != 2 {\n\t\treturn nil, fmt.Errorf(\"%s\", i18n.Tr(\"parser_invalid_ip_range_fmt\", rangeStr))\n\t}\n\n\tstartIPStr := strings.TrimSpace(parts[0])\n\tendIPStr := strings.TrimSpace(parts[1])\n\n\tstartIP := net.ParseIP(startIPStr)\n\tif startIP == nil {\n\t\treturn nil, fmt.Errorf(\"%s\", i18n.Tr(\"parser_invalid_start_ip\", startIPStr))\n\t}\n\n\t// 处理简写格式 (如: 192.168.1.1-100)\n\tif len(endIPStr) < 4 || !strings.Contains(endIPStr, \".\") {\n\t\treturn parseIPShortRange(startIPStr, endIPStr)\n\t}\n\n\t// 处理完整格式 (如: 192.168.1.1-192.168.1.100)\n\tendIP := net.ParseIP(endIPStr)\n\tif endIP == nil {","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/parsers/parsers.go#L326-L362","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide exactly one '-' separating start and end: 192.168.1.1-192.168.1.100","Remove extra hyphens or double dashes from the input","Pre-check strings.Count(s,\"-\") == 1 before calling ParseIP"],"exampleFix":"// before\nParseIP(\"192.168.1.1-100-200\", \"\")\n// after\nParseIP(\"192.168.1.1-200\", \"\")","handlingStrategy":"validation","validationCode":"func isTwoPartRange(s string) bool {\n\treturn strings.Count(s, \"-\") == 1 && len(strings.Split(s, \"-\")) == 2\n}","typeGuard":null,"tryCatchPattern":"if !isTwoPartRange(rangeStr) {\n\treturn fmt.Errorf(\"range %q must be start-end\", rangeStr)\n}\n_, err := parsers.ParseIP(rangeStr, \"\")","preventionTips":["Use exactly one '-' between start and end","Trim whitespace so no stray dashes remain inside tokens","Reject multi-dash inputs before calling ParseIP"],"tags":["ip-range","format-validation","ip-parsing"],"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-14T05:17:10.506Z"}