Skip to content

Improve scanner CLI stability and reporting#6

Open
abaskalov wants to merge 1 commit intoBeardedTek-com:mainfrom
abaskalov:improve-cli-stability-and-reporting
Open

Improve scanner CLI stability and reporting#6
abaskalov wants to merge 1 commit intoBeardedTek-com:mainfrom
abaskalov:improve-cli-stability-and-reporting

Conversation

@abaskalov
Copy link
Copy Markdown

Summary

  • fix multiple CLI/runtime issues so rtspscanner can initialize and complete scans without crashing in non-interactive runs
  • add port range support for --ports and RTSP_SCAN_PORTS, including mixed CSV/range input such as 554,8554,10000-10010
  • expand scan output with a summary of addresses, ports, socket checks, RTSP URL checks, and timeout settings, and document the new behavior in the README

Verification

  • tools/RTSPScanner/.venv/bin/python -m py_compile tools/RTSPScanner/rtspscanner.py
  • tools/RTSPScanner/.venv/bin/rtspscanner -m scan -a 127.0.0.1 -c admin:104194411 -p 554,8554,10000-10002

Copilot AI review requested due to automatic review settings April 21, 2026 07:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the rtspscanner CLI so it behaves more reliably in non-interactive runs, adds support for port ranges in --ports/RTSP_SCAN_PORTS, and expands scan output with a more detailed summary (also reflected in the README).

Changes:

  • Add port range parsing (e.g., 554,8554,10000-10010) and address counting for summary reporting.
  • Avoid non-interactive stty issues and make ffmpeg timeout handling/reporting more robust.
  • Expand CLI output with scan summary details and document the new output/port syntax in the README.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
rtspscanner.py Adds port range normalization, scan summary reporting, and safer non-interactive behavior.
README.md Documents port range syntax and includes the new “Scan Summary” output examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Paths tried per candidate: 2
RTSP URL checks: 8
Timeout per RTSP check: 10s
Timeout retries: 2
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example output shows "Timeout retries: 2", but the CLI default for --timeoutretries is currently 3 (and main() uses the CLI value). Update the README example to match the actual default/output, or change the default in code to 2 for consistency.

Suggested change
Timeout retries: 2
Timeout retries: 3

Copilot uses AI. Check for mistakes.
Comment thread README.md
Paths tried per candidate: 2
RTSP URL checks: 2
Timeout per RTSP check: 10s
Timeout retries: 2
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example output shows "Timeout retries: 2", but the CLI default for --timeoutretries is currently 3 (and main() uses the CLI value). Update the README example to match the actual default/output, or change the default in code to 2 for consistency.

Suggested change
Timeout retries: 2
Timeout retries: 3

Copilot uses AI. Check for mistakes.
Comment thread rtspscanner.py
Comment on lines +85 to +95
for value in self.splitCSV(ports):
value = value.strip()
if not value:
continue
if '-' not in value:
normalized.append(value)
continue

start, end = value.split('-', 1)
start = int(start.strip())
end = int(end.strip())
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizePorts() calls int() on user-provided range endpoints without any error handling or validation. Inputs like --ports 554,abc or 1000- will raise ValueError and crash the CLI; consider catching parsing errors and surfacing a clear argparse/CLI error, and validating the allowed port range (1-65535).

Suggested change
for value in self.splitCSV(ports):
value = value.strip()
if not value:
continue
if '-' not in value:
normalized.append(value)
continue
start, end = value.split('-', 1)
start = int(start.strip())
end = int(end.strip())
def parse_port(port_value, original_value):
port_value = port_value.strip()
if not port_value:
raise ValueError(f"Invalid port specification '{original_value}': missing port value")
try:
port = int(port_value)
except ValueError:
raise ValueError(f"Invalid port specification '{original_value}': '{port_value}' is not a valid integer")
if port < 1 or port > 65535:
raise ValueError(f"Invalid port specification '{original_value}': port {port} is outside the allowed range 1-65535")
return port
for value in self.splitCSV(ports):
value = value.strip()
if not value:
continue
if '-' not in value:
normalized.append(str(parse_port(value, value)))
continue
start, end = value.split('-', 1)
start = parse_port(start, value)
end = parse_port(end, value)

Copilot uses AI. Check for mistakes.
Comment thread rtspscanner.py
Comment on lines +83 to +100
def normalizePorts(self, ports):
normalized = []
for value in self.splitCSV(ports):
value = value.strip()
if not value:
continue
if '-' not in value:
normalized.append(value)
continue

start, end = value.split('-', 1)
start = int(start.strip())
end = int(end.strip())
if start > end:
start, end = end, start
normalized.extend(str(port) for port in range(start, end + 1))

return ','.join(normalized)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizePorts() expands ranges into an explicit list of every port, which can allocate very large lists/strings (e.g., 1-65535 or worse) and make the CLI slow or OOM. Consider enforcing a reasonable maximum range size and/or passing ranges through without full expansion (if PortScan can accept ranges) to avoid accidental resource exhaustion.

Copilot uses AI. Check for mistakes.
Comment thread rtspscanner.py
if flakyCount > 0:
CamDisp = "Cameras" if flakyCount > 1 else "Camera"
print(f"\n{len(scanner.scanResults['flaky'])} Flaky {CamDisp}:")
print(f"Potential {CamDisp.lower()} that cannot be verfied within {scanner.timeout} second timeout.")
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in user-facing output: "verfied" should be "verified".

Suggested change
print(f"Potential {CamDisp.lower()} that cannot be verfied within {scanner.timeout} second timeout.")
print(f"Potential {CamDisp.lower()} that cannot be verified within {scanner.timeout} second timeout.")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants