Skip to content

Add lightweight macOS port scanner tool#6

Open
CaptRCL wants to merge 4 commits intoUrinx:masterfrom
CaptRCL:claude/macos-port-scanner-RJvBJ
Open

Add lightweight macOS port scanner tool#6
CaptRCL wants to merge 4 commits intoUrinx:masterfrom
CaptRCL:claude/macos-port-scanner-RJvBJ

Conversation

@CaptRCL
Copy link
Copy Markdown

@CaptRCL CaptRCL commented Mar 3, 2026

  • Zero-dependency Python 3 implementation using stdlib only
  • Multi-threaded TCP scanning with configurable thread count
  • Supports port ranges, comma-separated lists, and top-100 preset
  • Service identification for 80+ common ports
  • Optional banner grabbing for service fingerprinting
  • Color terminal output with scan summary

https://claude.ai/code/session_01DGJrP8B7ohyiEG1h1khr4f

claude added 4 commits March 3, 2026 01:57
- Zero-dependency Python 3 implementation using stdlib only
- Multi-threaded TCP scanning with configurable thread count
- Supports port ranges, comma-separated lists, and top-100 preset
- Service identification for 80+ common ports
- Optional banner grabbing for service fingerprinting
- Color terminal output with scan summary

https://claude.ai/code/session_01DGJrP8B7ohyiEG1h1khr4f
Limit concurrent socket connections to 50 via threading.Semaphore to
prevent macOS from killing the process (Killed: 9) when too many file
descriptors are opened simultaneously during a scan.

https://claude.ai/code/session_01DGJrP8B7ohyiEG1h1khr4f
Lower semaphore from 50 to 30 and default thread count from 100 to 50
to stay well below macOS's default fd limit of 256 per process.

https://claude.ai/code/session_01DGJrP8B7ohyiEG1h1khr4f
…fix worker race condition

Three root causes fixed:
1. scan socket was still open while grab_banner() opened a second socket,
   doubling actual concurrent FDs; moved grab_banner() call after the
   `with socket` block so the scan socket is always closed first
2. worker() used `while not queue.empty()` + `queue.get()` — a TOCTOU
   race where threads could block indefinitely on get(); replaced with
   queue.get(block=False) + Empty exception
3. semaphore was a fixed global (30) independent of thread count; now
   created dynamically in run_scan() as min(threads, 20) so the limit
   always matches actual concurrency; default threads lowered 50→20
4. added _raise_fd_limit() to programmatically raise macOS fd soft limit
   to 2048 at startup

https://claude.ai/code/session_01DGJrP8B7ohyiEG1h1khr4f
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