{"id":39050874,"url":"https://github.com/pratik-anurag/portik","last_synced_at":"2026-01-26T15:01:29.032Z","repository":{"id":332897867,"uuid":"1131804381","full_name":"pratik-anurag/portik","owner":"pratik-anurag","description":"CLI to inspect, explain, and manage port ownership.","archived":false,"fork":false,"pushed_at":"2026-01-16T16:22:50.000Z","size":128,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-16T19:51:30.161Z","etag":null,"topics":["cli","port"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pratik-anurag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-10T18:17:05.000Z","updated_at":"2026-01-16T19:03:59.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pratik-anurag/portik","commit_stats":null,"previous_names":["pratik-anurag/portik"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pratik-anurag/portik","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratik-anurag%2Fportik","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratik-anurag%2Fportik/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratik-anurag%2Fportik/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratik-anurag%2Fportik/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pratik-anurag","download_url":"https://codeload.github.com/pratik-anurag/portik/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratik-anurag%2Fportik/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28781308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","port"],"created_at":"2026-01-17T17:57:05.404Z","updated_at":"2026-01-26T15:01:29.027Z","avatar_url":"https://github.com/pratik-anurag.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# portik\n\n[![ci](../../actions/workflows/ci.yml/badge.svg)](../../actions/workflows/ci.yml)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/portik-logo.svg\" alt=\"portik logo\" width=\"640\" /\u003e\n\u003c/p\u003e\n\nA developer-friendly CLI to inspect, explain, and manage port ownership. Find out who's using a port, why it's stuck, and how to safely recover it.\n\n## Quick Start\n\n```bash\nportik who 5432        # Who owns the port?\nportik explain 5432    # Why is it stuck?\nportik kill 5432       # Safely terminate the owner\nportik restart 5432    # Stop and restart the last command\n```\n\n## Key Features\n\n- **Inspect**: Show all listeners on a port (PID, user, process, command)\n- **Diagnose**: Explain why a port is stuck (TIME_WAIT, zombies, permissions, IPv4/IPv6 confusion)\n- **Manage**: Kill, restart, or reserve ports safely\n- **Monitor**: Watch ownership changes, view history, trace process trees\n- **Docker**: Show container-to-port mappings\n- **Lint**: Flag security issues (ports exposed to 0.0.0.0, privileged ports, etc.)\n\n## Installation\n\n### Using `go install` (Recommended)\n\nRequires Go 1.24+:\n\n```bash\n# Standard installation\ngo install github.com/pratik-anurag/portik@latest\n\n# With TUI support\ngo install -tags tui github.com/pratik-anurag/portik@latest\n```\n\n### Build from Source\n\n```bash\n# Build locally\ngo build .\n./portik --help\n\n# Install globally\ngo install .\n```\n\n### Homebrew / Binaries\n\nComing soon.\n\n## Requirements\n\n- **Go 1.24+** (for building)\n- **Linux**: `ss` and `ps` in PATH\n- **macOS**: `lsof` and `ps` in PATH (elevated privileges recommended)\n- **Optional**: `docker` CLI for `--docker` features\n\n## Common Commands\n\n### Inspect Port Ownership\n\n```bash\nportik who 5432                          # Who owns the port?\nportik who 5432 --docker                 # Include Docker mapping\nportik who 5432 --follow --interval 2s   # Watch for changes\n```\n\n### Diagnose Problems\n\n```bash\nportik explain 5432      # Why is it stuck?\nportik explain 5432 --docker\nportik lint              # Find security issues across all listeners\n```\n\n### Manage Ports\n\n```bash\nportik kill 5432         # Gracefully terminate, then force kill\nportik restart 5432      # Smart restart (captures and replays command)\nportik wait 8080 --listening --timeout 60s   # Wait for service to start\n```\n\n### Monitor \u0026 History\n\n```bash\nportik watch 5432 --interval 10s         # Record ownership changes\nportik history 5432 --since 7d           # View recent history\nportik history 5432 --detect-patterns    # Detect patterns\nportik daemon --ports 5432,6379 --interval 30s --docker\n```\n\n### Find Free Ports\n\n```bash\nportik free                               # Get an ephemeral free port\nportik free --ports 3000-3999            # Find free port in range\nportik reserve 5432 --for 2m             # Reserve port for duration\nportik use --ports 3000-3999 -- npm run dev   # Run command on free port\n```\n\n### Scan Ports\n\n```bash\nportik scan --ports 3000-3010            # Scan range\nportik scan --ports 22,80,443,5432       # Scan list\nportik scan --all                         # Scan ALL listening ports on system\nportik scan --all --owner postgres       # Filter by owner\nportik scan --all --min-port 3000 --max-port 9999  # Filter by port range\nportik top --ports 3000-3010 --top 5     # Top ports by connection count\n```\n\n### Trace \u0026 Debug\n\n```bash\nportik blame 5432        # Process tree (who started this?)\nportik trace 5432        # Trace ownership/proxy layers\nportik conn 5432 --top 10   # Top clients to a port\n```\n\n## Command Reference\n\n| Command | Description |\n|---------|-------------|\n| `who` | Show listeners on a port |\n| `explain` | Diagnose why a port is stuck |\n| `kill` | Gracefully terminate port owner |\n| `restart` | Smart restart (stop + replay command) |\n| `watch` | Poll and record ownership changes |\n| `daemon` | Monitor multiple ports continuously |\n| `history` | View ownership history in time window |\n| `blame` | Show process tree and \"who started this\" |\n| `trace` | Trace ownership/proxy layers |\n| `top` | Top ports by connection count |\n| `scan` | Scan ports (range/list or discover all with `--all`) |\n| `free` | Find a free port |\n| `reserve` | Reserve a port temporarily |\n| `use` | Run command on a free port |\n| `conn` | Show connections to a port |\n| `wait` | Wait for port to become listening/free |\n| `lint` | Lint current listeners for issues |\n| `tui` | Interactive port management (optional) |\n\n## TUI (Interactive Dashboard)\n\nOptional interactive interface (like `htop` for ports):\n\n```bash\n# Run directly\ngo run -tags tui . tui --ports 5432,6379 --interval 2s\n\n# Or build binary with TUI enabled\ngo build -tags tui -o portik .\n./portik tui --ports 5432,6379 --interval 2s --docker\n```\n\n### TUI Keybindings\n\n- **↑/↓** or **j/k** — Move selection\n- **Tab** — Toggle Who/Explain views\n- **w** — Who view\n- **e** — Explain view\n- **r** — Refresh now\n- **/** — Filter/search\n- **Esc** — Clear filter/cancel\n- **?** / **h** — Toggle help\n- **q** — Quit\n- **K** — Kill (with `--actions`)\n- **R** — Restart (with `--actions`)\n\n## Platform Support\n\n- **Linux** — uses `ss` and `ps`\n- **macOS** — uses `lsof` and `ps` (elevated privileges recommended)\n- **Windows** — not fully supported yet\n\n## Troubleshooting\n\n| Problem | Solution |\n|---------|----------|\n| \"Address already in use\" after restart | Run `portik explain \u003cport\u003e` for TIME_WAIT sockets; retry after delay |\n| No PID shown | Re-run with `sudo` and ensure `lsof`/`ss` is available |\n| Port unreachable from remote machine | Check for loopback-only listeners; bind to `0.0.0.0` or `[::]` |\n| Container port confusion | Use `portik who \u003cport\u003e --docker` to see host-to-container mappings |\n| Port listening but unreachable | Check local firewall and allow the port |\n| Missing PID/cmdline | Elevated privileges (sudo) required on macOS and some Linux systems |\n\n## Common Issues\n\n**Why does portik need `sudo`?**  \nSocket-to-PID resolution is restricted without elevated privileges on macOS and some Linux systems.\n\n**Can portik manage container ports?**  \nYes, use `--docker` flag. It shows host-to-container mappings and container names.\n\n**What if I need to track history?**  \nHistory is stored at `~/.portik/history.json`. Use `portik history` to view it. History is safely managed:\n- Up to 200 entries per port (oldest discarded when limit reached)\n- Safe concurrent writes if multiple portik daemons/watches are running\n- Deduplicates consecutive identical states to reduce file growth\n\n**Can I run multiple portik daemons simultaneously?**  \nYes, they're safe to run concurrently. History writes are serialized with a mutex to prevent corruption.\n\n**Is it safe to use kill/restart?**  \nYes. Both commands are conservative by default:\n- Require confirmation (unless `--yes`)\n- Refuse to act on processes not owned by your user (unless `--force`)\n\n## Permissions \u0026 Safety\n\nDestructive actions (kill, restart, TUI actions) are conservative by default:\n\n- ✓ Confirmation prompts (unless `--yes`)\n- ✓ Refuse to act on processes not owned by you (unless `--force`)\n- ✓ Use `sudo` when needed for full PID/cmdline visibility\n\n## Design \u0026 Limitations\n\n**Design:**\n- Port inspection is OS-specific (Linux: `ss`, macOS: `lsof`; results normalized)\n- Process metadata enriched via `ps` parsing\n- Diagnostics are heuristic to guide debugging, not replace system analysis\n- History writes are serialized with a mutex to ensure concurrent safety across multiple processes\n\n**History Management:**\n- Per-port limit: 200 entries (oldest discarded when exceeded)\n- Consecutive identical states are deduplicated to reduce file growth\n- Multiple daemons/watches can run concurrently without corruption\n- Lock timeout: 7 seconds (falls back gracefully if timeout exceeded)\n- File location: `~/.portik/history.json`\n\n**Limitations:**\n- Socket → PID resolution requires elevated privileges in some cases\n- Docker mapping relies on local `docker` CLI; not exhaustive for all runtimes\n- `restart` relies on recorded command history; may not reproduce complex environments\n- History stored in single JSON file; very large histories may be slow to query\n- Global per-port limit (200 entries) may be insufficient for long-running monitoring\n\n## Contributing\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md). Please keep behavior conservative and maintain backward compatibility for JSON output.\n\n## License\n\nMIT — See [LICENSE](./LICENSE).\n\n## Project Status\n\n**Alpha**. Active development. Interfaces and JSON output may change. The focus is on correctness over exhaustive platform coverage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratik-anurag%2Fportik","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpratik-anurag%2Fportik","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratik-anurag%2Fportik/lists"}