{"record":{"id":"d84c360c7fce118c","repo":"urbanadventurer/WhatWeb","slug":"error-parsing-target-ip-range-e","errorCode":null,"errorMessage":"Error parsing target IP range: #{e}","messagePattern":"Error parsing target IP range: #(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/whatweb/scan.rb","lineNumber":229,"sourceCode":"        if x =~ %r{^[0-9\\.\\-\\/]+$} && x !~ %r{^[\\d\\.]+$}\n          begin\n            # CIDR notation\n            if x =~ %r{\\d+\\.\\d+\\.\\d+\\.\\d+/\\d+$}\n              range = IPAddr.new(x).to_range.map(&:to_s)\n            # x.x.x.x-x\n            elsif x =~ %r{^(\\d+\\.\\d+\\.\\d+\\.\\d+)-(\\d+)$}\n              start_ip = IPAddr.new(Regexp.last_match(1), Socket::AF_INET)\n              end_ip   = IPAddr.new(\"#{start_ip.to_s.split('.')[0..2].join('.')}.#{Regexp.last_match(2)}\", Socket::AF_INET)\n              range = (start_ip..end_ip).map(&:to_s)\n            # x.x.x.x-x.x.x.x\n            elsif x =~ %r{^(\\d+\\.\\d+\\.\\d+\\.\\d+)-(\\d+\\.\\d+\\.\\d+\\.\\d+)$}\n              start_ip = IPAddr.new(Regexp.last_match(1), Socket::AF_INET)\n              end_ip   = IPAddr.new(Regexp.last_match(2), Socket::AF_INET)\n              range = (start_ip..end_ip).map(&:to_s)\n            end\n          rescue => e\n            # Something went horribly wrong parsing the target IP range\n            raise \"Error parsing target IP range: #{e}\"\n          end\n        end\n        range\n      end.compact.flatten\n\n      # TODO: refactor this. data which matches these regexs should be taken care of above\n      url_list = url_list.select { |x| !(x =~ %r{^[0-9\\.\\-*\\/]+$}) || x =~ /^[\\d\\.]+$/ }\n      url_list += ip_range unless ip_range.empty?\n\n      # make urls friendlier, test if it's a file, if test for not assume it's http://\n      # http, https, ftp, etc\n      push_to_urllist = []\n      consecutive_errors = 0\n      inputfile_name = opts[:input_file] # Store for error messages\n      \n      # TODO: refactor this\n      url_list = url_list.map do |x|\n        if File.exist?(x)","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/urbanadventurer/WhatWeb/blob/d279d93042d034f3fd29d5a893d44ccc0595d3f8/lib/whatweb/scan.rb#L211-L247","documentation":"When WhatWeb parses a target string that looks like an IP range (e.g. 192.168.1.1-192.168.1.254), make_target_list converts the endpoints with IPAddr. Any exception raised during this parsing (malformed IP text, reversed/invalid ranges) is re-raised as 'Error parsing target IP range: <original error>'. The original exception message is embedded, so read it for the root cause.","triggerScenarios":"Passing a malformed IP range on the command line or in the target list: non-numeric octets (192.168.1.x-192.168.1.20), extra characters, IPv6 text matched by the IPv4 regex, or an end IP smaller than start IP in downstream logic.","commonSituations":"Typoed CIDR/range syntax by the operator (dash vs colon, stray spaces); copy-pasted ranges with whitespace or trailing characters; scripts interpolating unvalidated host ranges into the target argument.","solutions":["Read the embedded inner error and correct the offending range string to strict dotted-quad form, e.g. 192.168.1.1-192.168.1.254","Validate the range with IPAddr before passing it to WhatWeb (rescue IPAddr::InvalidAddressError yourself)","Use CIDR notation instead when possible (192.168.1.0/24), which avoids the range parser","Split comma-separated targets and check each individually to isolate the bad one"],"exampleFix":"// before\nwhatweb 192.168.1.1-192.168.1..254\n// after\nwhatweb 192.168.1.1-192.168.1.254","handlingStrategy":"validation","validationCode":"require 'ipaddr'\ndef valid_ip_range?(s)\n  m = s.match(/\\A([\\d.]+)-([\\d.]+)\\z/)\n  return false unless m\n  IPAddr.new(m[1], Socket::AF_INET)\n  IPAddr.new(m[2], Socket::AF_INET)\n  true\nrescue IPAddr::InvalidAddressError\n  false\nend","typeGuard":"def dotted_quad?(s)\n  /\\A(\\d{1,3}\\.){3}\\d{1,3}\\z/.match?(s)\nend","tryCatchPattern":"begin\n  WhatWeb::Scanner.new([range_target])\nrescue RuntimeError => e\n  raise unless e.message.start_with?('Error parsing target IP range:')\n  warn \"Fix range syntax: #{e.message}\"\nend","preventionTips":["Use strict dotted-quad ranges with a single dash and no spaces","Prefer CIDR notation (a.b.c.d/nn) to avoid the range parser entirely","Sanitize targets read from files: strip whitespace and reject blanks","Pre-validate with IPAddr.new before invoking WhatWeb"],"tags":["ruby","whatweb","ip-range","target-parsing","cli"],"backgroundTag":"invalid-argument-format","analyzedSha":"d279d93042d034f3fd29d5a893d44ccc0595d3f8","analyzedAt":"2026-09-15T13:51:42.453Z","contentChangedAt":"2026-09-15T13:51:42.453Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}