PortZap is a command-line utility written in Dart that helps you manage and terminate processes running on specific ports. It's cross-platform, supporting Windows, macOS, and Linux.
- List all running ports and their associated process IDs
- Kill a process running on a specific port
- Cross-platform support (Windows, macOS, Linux)
- Ensure you have Dart SDK installed on your system.
- Clone this repository or download the
portzap.dart
file. - Run
dart pub get
to install dependencies.
dart run bin/portzap.dart [-p <port_number> | -l] [-h]
-p, --port
: Specify the port number to kill the process on-l, --list
: List all running ports and their associated PIDs-h, --help
: Show usage information
-
List all running ports:
dart run bin/portzap.dart -l
-
Kill a process running on port 8080:
dart run bin/portzap.dart -p 8080
-
Show help information:
dart run bin/portzap.dart -h
-
Parsing arguments: The script uses the
args
package to parse command-line arguments, allowing users to specify options like port number, listing ports, or showing help. -
Listing ports:
- On Windows: Uses
netstat -ano
to list all TCP/IP network connections and their associated processes. - On macOS/Linux: Uses
lsof -i -P -n
to list open files and network connections.
The output is then parsed to extract port numbers and process IDs.
- On Windows: Uses
-
Killing a process on a specific port:
- First, it identifies the process ID (PID) associated with the given port:
- On Windows: Uses
netstat -ano | findstr :<port>
- On macOS/Linux: Uses
lsof -i :<port> -t
- On Windows: Uses
- Then, it terminates the process using the appropriate command:
- On Windows:
taskkill /F /PID <pid>
- On macOS/Linux:
kill -9 <pid>
- On Windows:
- First, it identifies the process ID (PID) associated with the given port:
-
Error handling: The script includes error handling to manage issues like invalid input, unsupported platforms, or failed operations.
- This tool requires appropriate permissions to list and terminate processes. On some systems, you may need to run it with elevated privileges (e.g., using
sudo
on macOS/Linux). - Always use caution when terminating processes, especially on production systems.
Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.