Skip to main content

A fast and elegant command-line utility for inspecting and managing TCP ports on macOS and Linux

Project description

lsport

A fast and elegant command-line utility for inspecting and managing TCP ports on macOS and Linux.

License: MIT Python 3.9+

What is lsport?

lsport helps you quickly identify which processes are occupying TCP ports and terminate them when needed. It provides three modes of operation:

  • List mode: View all open TCP ports with process details
  • Kill mode: Terminate a process occupying a specific port
  • Interactive mode: Browse and manage ports through a TUI menu

Features

  • ๐Ÿš€ Fast port scanning using psutil
  • ๐ŸŽจ Beautiful terminal output with rich
  • ๐Ÿ” Filter by port state (LISTEN, ESTABLISHED, CLOSE_WAIT)
  • ๐Ÿ›ก๏ธ Safe: asks for confirmation before killing processes
  • ๐Ÿ’ช Force kill option for stubborn processes
  • ๐Ÿ“Š Interactive TUI for easy port management

Requirements

  • macOS or Linux
  • Python 3.9 or higher
  • pipx (one-time install)

Installation

lsport is distributed as a standard Python package and installed in an isolated environment via pipx. This avoids polluting your system Python, never touches sudo, and gives you a clean pipx uninstall lsport when you're done.

1. Install pipx (one-time)

macOS:

brew install pipx
pipx ensurepath

Linux (Debian/Ubuntu):

sudo apt install pipx
pipx ensurepath

For other distributions or platforms see the pipx installation guide.

2. Install lsport

git clone https://github.com/0xBroom/lsport.git
cd lsport
pipx install .

That's it. lsport is now available on your PATH, with its dependencies isolated in a dedicated virtual environment under ~/.local/share/pipx/.

Updating

cd lsport
git pull
pipx install . --force

Uninstalling

pipx uninstall lsport

Usage

List all open ports

lsport list

Output example:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Port โ”‚ Protocol    โ”‚ State    โ”‚ PID  โ”‚ Process        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 3000 โ”‚ 0.0.0.0:3000โ”‚ LISTEN   โ”‚ 1234 โ”‚ node           โ”‚
โ”‚ 5432 โ”‚ 127.0.0.1:* โ”‚ LISTEN   โ”‚ 5678 โ”‚ postgres       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Filter by state

# Show only listening ports
lsport list --state listen

# Show active connections
lsport list --state established

# Show ports in close_wait state
lsport list --state close_wait

Kill a process on a specific port

# Interactive kill (asks for confirmation)
lsport kill 3000

# Skip confirmation
lsport kill 3000 --yes

# Force kill (SIGKILL instead of SIGTERM)
lsport kill 3000 --force

Interactive mode

lsport interactive

Navigate the interactive TUI to:

  • Browse all LISTEN ports
  • Select ports by row number or port number
  • Kill processes with confirmation

Command Reference

lsport list

Lists all open TCP ports.

Options:

  • -s, --state [listen|established|close_wait] - Filter by connection state

lsport kill <port>

Terminates the process occupying the specified port.

Options:

  • -f, --force - Use SIGKILL instead of SIGTERM
  • -y, --yes - Skip confirmation prompt

lsport interactive

Launch an interactive TUI to browse and manage ports.

Development

Project structure

lsport/
โ”œโ”€โ”€ lsport.py      # Main CLI application
โ”œโ”€โ”€ pyproject.toml  # Package metadata and entry point
โ”œโ”€โ”€ LICENSE         # MIT License
โ””โ”€โ”€ README.md       # This file

Dependencies

  • psutil - Process and system utilities
  • typer - CLI framework
  • rich - Terminal formatting and TUI

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Created by Esteban Encina

Acknowledgments

  • Built with Typer and Rich
  • Inspired by the need for a fast, native port management tool for the terminal

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lsport-0.3.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lsport-0.3.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file lsport-0.3.0.tar.gz.

File metadata

  • Download URL: lsport-0.3.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lsport-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9e2026acaef5bb26a7ecdcd682a9c1d8f74c5089031fdd4f28b375a438d2ba22
MD5 f620ea0da1b32e894d95ae4a914b0023
BLAKE2b-256 90d8c4f3b4bb70441ec235afe5e067503fab49de0debae8a0687070cb2087381

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsport-0.3.0.tar.gz:

Publisher: release.yml on 0xBroom/lsport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lsport-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lsport-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lsport-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80205eff4bdfe64c9c14a15f39b9b6e7ab5f6be4952e4b74a6e92a88870509ee
MD5 8010ab8fe6f390d83ba74da88f84017d
BLAKE2b-256 5e5604a01f389714c51834bba1867383405d13f84a3b90bcac118ee3b8e5530d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsport-0.3.0-py3-none-any.whl:

Publisher: release.yml on 0xBroom/lsport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page