port-checker

Crates.ioport-checker
lib.rsport-checker
version0.3.0
created_at2025-07-22 03:34:51.344378+00
updated_at2025-07-28 02:49:56.530711+00
descriptionA fast and user-friendly command-line tool to check port usage
homepagehttps://github.com/william-xue/port-checker
repositoryhttps://github.com/william-xue/port-checker
max_upload_size
id1762936
size125,771
Cheemi (william-xue)

documentation

README

Port Checker ๐Ÿ”

A fast and user-friendly command-line tool to check port usage on your system. Built with Rust for maximum performance and reliability.

Features

  • ๐Ÿš€ Fast: Blazingly fast port scanning with minimal system overhead
  • ๐ŸŽจ Beautiful Output: Colorized and well-formatted terminal output
  • ๐Ÿ” Comprehensive: Check TCP, UDP, IPv4, and IPv6 connections
  • ๐Ÿ“Š Statistics: View detailed port usage statistics
  • ๐Ÿ”Ž Process Detection: Find which process is using a specific port
  • ๐Ÿ“‹ Multiple Formats: Output in table, JSON, YAML, or CSV format
  • โš™๏ธ Configuration File: Customizable settings with TOML configuration
  • ๐ŸŒ Cross-Platform: Works on Linux, macOS, and Windows
  • ๐Ÿš€ Concurrent Scanning: High-performance parallel port scanning
  • ๐ŸŽฏ Smart Port Allocation: Automatically find and allocate available ports
  • ๐Ÿ”’ Port Reservation: Reserve ports and bind them to process lifecycles
  • ๐Ÿ”— Process Integration: Run commands with pre-allocated ports

Installation

From crates.io (Recommended)

cargo install port-checker

From source

git clone https://github.com/william-xue/port-checker.git
cd port-checker
cargo install --path .

Pre-built binaries

Download the latest release from the releases page.

Usage

List all occupied ports

# List all ports
port-checker list

# List only TCP ports
port-checker list --protocol tcp

# List only listening ports
port-checker list --listening

# Output in different formats
port-checker list --format json
port-checker list --format yaml
port-checker list --format csv
port-checker list --format table  # default

Check if a specific port is in use

# Check port 8080 (both TCP and UDP)
port-checker check 8080

# Check port 8080 TCP only
port-checker check 8080 --protocol tcp

Find which process is using a port

# Find process using TCP port 8080
port-checker find 8080

# Find process using UDP port 53
port-checker find 53 --protocol udp

Kill a process using a port

# Kill process using TCP port 8080
port-checker kill 8080

# Kill process using UDP port 53
port-checker kill 53 --protocol udp

Show port usage statistics

port-checker stats

Smart port allocation

# Allocate a random available port in range
port-checker pick --start 8000 --end 9000

# Keep the port reserved (don't exit immediately)
port-checker pick --start 8080 --end 8090 --keep

Reserve a specific port

# Reserve a port temporarily
port-checker reserve 8888

# Reserve a port and run a command with it
port-checker reserve 8888 --command "python3 -m http.server"

# Keep the port reserved after command exits
port-checker reserve 8888 --command "node server.js" --keep

Configuration Management

# Show current configuration
port-checker config show

# Initialize default configuration file
port-checker config init

# Use custom configuration file
port-checker list --config /path/to/config.toml

# Override settings with command line options
port-checker list --format yaml --verbose

Examples

Example Output

$ port-checker list --listening
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Protocol โ”‚ Local Address   โ”‚ Remote Address  โ”‚ State   โ”‚ PID  โ”‚ Process Name โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ TCP      โ”‚ 0.0.0.0:22      โ”‚ -               โ”‚ LISTEN  โ”‚ 1234 โ”‚ sshd         โ”‚
โ”‚ TCP      โ”‚ 127.0.0.1:5432  โ”‚ -               โ”‚ LISTEN  โ”‚ 5678 โ”‚ postgres     โ”‚
โ”‚ TCP      โ”‚ 0.0.0.0:80      โ”‚ -               โ”‚ LISTEN  โ”‚ 9012 โ”‚ nginx        โ”‚
โ”‚ TCP      โ”‚ 0.0.0.0:443     โ”‚ -               โ”‚ LISTEN  โ”‚ 9012 โ”‚ nginx        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Total: 4 ports found
$ port-checker check 8080
๐ŸŸข Port 8080 (TCP) is FREE
๐ŸŸข Port 8080 (UDP) is FREE
$ port-checker find 22
๐Ÿ” Process using port 22 (TCP):

  Process ID: 1234
  Process Name: sshd
  Local Address: 0.0.0.0:22
  State: LISTEN
$ port-checker pick --start 8080 --end 8090
๐ŸŽฒ Allocating random port in range 8080..8090
โœ… Successfully allocated port: 8085
  Address: 127.0.0.1:8085
  Protocol: TCP

โšก Port 8085 allocated successfully. Use it quickly before this program exits!
๐Ÿ’ก Press Enter to release the port...
$ port-checker reserve 8888 --command "python3 -m http.server"
๐Ÿ”’ Reserving port 8888 (TCP)
โœ… Port 8888 successfully reserved
๐Ÿš€ Starting command: python3 -m http.server
โœ… Command started with PID: 12345
โณ Waiting for command to complete...
Serving HTTP on 0.0.0.0 port 8888 (http://0.0.0.0:8888/) ...

Command Reference

Global Options

These options are available for all commands:

  • -f, --format <FORMAT>: Output format (table, json, yaml, csv)
  • -c, --config <FILE>: Use custom configuration file
  • -v, --verbose: Enable verbose output

port-checker list [OPTIONS]

List all occupied ports on the system.

Options:

  • -p, --protocol <PROTOCOL>: Filter by protocol (tcp/udp)
  • -l, --listening: Show only listening ports

port-checker check <PORT> [OPTIONS]

Check if a specific port is in use.

Arguments:

  • <PORT>: Port number to check

Options:

  • -p, --protocol <PROTOCOL>: Protocol to check (tcp/udp)

port-checker find <PORT> [OPTIONS]

Find the process using a specific port.

Arguments:

  • <PORT>: Port number to find

Options:

  • -p, --protocol <PROTOCOL>: Protocol type (default: tcp)

port-checker kill <PORT> [OPTIONS]

Kill the process using a specific port.

Arguments:

  • <PORT>: Port number to find the process to kill

Options:

  • -p, --protocol <PROTOCOL>: Protocol type (default: tcp)

port-checker stats

Display port usage statistics.

port-checker pick [OPTIONS]

Allocate a random available port in specified range.

Options:

  • -s, --start <START>: Start of port range (default: 8000)
  • -e, --end <END>: End of port range (default: 9000)
  • -k, --keep: Keep the port reserved (don't exit immediately)

port-checker reserve <PORT> [OPTIONS]

Reserve a specific port and optionally run a command.

Arguments:

  • <PORT>: Port number to reserve

Options:

  • -p, --protocol <PROTOCOL>: Protocol (tcp/udp) (default: tcp)
  • -c, --command <COMMAND>: Command to run with the reserved port
  • -k, --keep: Keep the port reserved after command exits

port-checker config <ACTION>

Manage configuration settings.

Actions:

  • show: Display current configuration
  • init: Create default configuration file at ~/.config/port-checker/config.toml
  • set: Set configuration values (planned feature)

Configuration File

Port Checker supports configuration files in TOML format. The default location is ~/.config/port-checker/config.toml.

Example Configuration

# Default output format
default_format = "Table"  # Table, Json, Yaml, Csv

# Scan timeout in seconds
scan_timeout = 30

# Number of concurrent threads for scanning
concurrent_threads = 4

# Enable verbose output by default
verbose = false

# Show process information
show_process_info = true

# Default reserve duration in seconds
default_reserve_duration = 3600  # 1 hour

# Port allocation range
[port_range]
start = 8000
end = 9000

Configuration Priority

  1. Command-line arguments (highest priority)
  2. Custom config file specified with --config
  3. Default config file (~/.config/port-checker/config.toml)
  4. Built-in defaults (lowest priority)

Requirements

  • Linux: No additional requirements
  • macOS: No additional requirements
  • Windows: Requires netstat and tasklist commands (included by default)

Performance

Port Checker is designed to be fast and lightweight:

  • โšก Scans thousands of ports in milliseconds
  • ๐Ÿ’พ Minimal memory usage
  • ๐Ÿ”‹ Low CPU overhead
  • ๐Ÿ“Š Efficient data structures

Contributing

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

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

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

Acknowledgments

  • Built with clap for command-line parsing
  • Uses colored for terminal colors
  • Table formatting with tabled

๐Ÿš€ Roadmap

โœ… Completed Features

  • Configuration file support (TOML)
  • Multiple output formats (Table, JSON, YAML, CSV)
  • Concurrent port scanning
  • Cross-platform support
  • Process information detection
  • Port reservation system
  • Smart port allocation
  • Process integration

๐Ÿšง Planned Features

ๆˆ‘ไปฌๆญฃๅœจ็งฏๆžๅผ€ๅ‘ไปฅไธ‹้ซ˜็บงๅŠŸ่ƒฝ๏ผŒ่ฎฉ Port Checker ๆˆไธบๆ›ดๅผบๅคง็š„็ฝ‘็ปœ่ฏŠๆ–ญๅทฅๅ…ท๏ผš

โšก ้ซ˜ๆ€ง่ƒฝๆ‰ซๆ

# ๆ‰ซๆ็ฝ‘ๆฎต็š„็ซฏๅฃ่Œƒๅ›ด
port-checker scan 192.168.1.0/24 --ports 1-1000

# ไฝฟ็”จ้ข„่ฎพๆ‰ซๆๅธธ่งๆœๅŠก็ซฏๅฃ
port-checker scan --preset web
port-checker scan --preset database

๐Ÿ“Š ็›‘ๆŽงๆจกๅผ

# ๆŒ็ปญ็›‘ๆŽงๆŒ‡ๅฎš็ซฏๅฃ
port-checker monitor --watch 80,443 --alert

# ๅฎžๆ—ถไปช่กจๆฟ
port-checker dashboard --refresh 1s

๐Ÿ” ๆœๅŠก่ฏ†ๅˆซ

# ่ฏ†ๅˆซ็ซฏๅฃไธŠ่ฟ่กŒ็š„ๆœๅŠก
port-checker identify 80 --fingerprint

# ๅฅๅบทๆฃ€ๆŸฅ้ข„่ฎพๆœๅŠก
port-checker health-check --preset database

๐Ÿ“‹ ้ข„่ฎพ้…็ฝฎ

  • web: 80, 443, 8080, 8443, 3000, 5000
  • database: 3306, 5432, 27017, 6379
  • development: 3000, 8000, 8080, 9000
  • security: 22, 443, 993, 995

่ฟ™ไบ›ๅŠŸ่ƒฝๅฐ†ๅœจๅŽ็ปญ็‰ˆๆœฌไธญ้€ๆญฅๅ‘ๅธƒ๏ผŒๆ•ฌ่ฏทๆœŸๅพ…๏ผ

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Commit count: 0

cargo fmt