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.

PyPI version Python versions Downloads License: MIT

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 published on PyPI 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

pipx install lsport

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

Updating

pipx upgrade lsport

Uninstalling

pipx uninstall lsport

Install from source

If you want to run a development build from a local clone (useful for contributing โ€” see CONTRIBUTING.md):

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

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.1.tar.gz (10.3 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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lsport-0.3.1.tar.gz
  • Upload date:
  • Size: 10.3 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.1.tar.gz
Algorithm Hash digest
SHA256 4c7e810549c0ff92f19f1e5fc511435452585858161c383f0e6efc7e0d98757f
MD5 d51ceb54b58f4a284f352d7124ee7ddb
BLAKE2b-256 a08706fc95d88410ed7d70ff9e654874547d644c0c79dd6ba7bf2e53b9866ef1

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsport-0.3.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: lsport-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8631068d48730cef7bc25ad7f08221f1bc69b14745bf9ac4359a97c36893962a
MD5 d82c23980fa4c56c3328fe5da9303d30
BLAKE2b-256 9fe6fd6610823c16b588655d74fcffa22490f5312d67d3299aed0ac4951d904f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsport-0.3.1-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