PortWatch is a simple cross-platform Go application that lists active network connections (TCP and UDP) on your system, including details like protocol, local and remote addresses, connection state, process ID (PID), and process name.
- Cross-platform: Works on Linux and Windows.
- Connection Details: Displays protocol (TCP/UDP), local address, remote address, state (LISTEN, ESTABLISHED, CLOSED), PID, and process name.
- Color-coded States: Uses colors to highlight connection states (green for LISTEN, blue for ESTABLISHED, red for CLOSED).
- Real-time Data: Fetches live network connection information.
- Linux: Reads from
/proc/net/tcpand/proc/net/udpfor connection data. - Windows: Uses
netstat -anocommand to retrieve connection information. - Other OS: Displays an "Unsupported operating system" message.
- Go 1.16 or later.
- Dependencies:
github.com/fatih/color(automatically installed viago mod).
-
Clone the repository:
git clone https://github.com/yourusername/portwatch.git cd portwatch -
Install dependencies:
go mod tidy
Run the application directly:
go run main.goOr build and run:
go build -o portwatch main.go
./portwatchProto Local Address Remote Address State PID Process
TCP 0.0.0.0:80 0.0.0.0:0 LISTEN 1234 nginx
TCP 192.168.1.100:54321 93.184.216.34:443 ESTABLISHED 5678 chrome
UDP 0.0.0.0:53 0.0.0.0:0 CLOSED - -
- Proto: Protocol (TCP or UDP).
- Local Address: Local IP and port.
- Remote Address: Remote IP and port.
- State: Connection state (LISTEN, ESTABLISHED, CLOSED).
- PID: Process ID associated with the connection.
- Process: Name of the process.
- On Linux: Parses
/proc/net/tcpand/proc/net/udpfiles, then maps inodes to PIDs via/proc/*/fd/*and retrieves process names from/proc/*/comm. - On Windows: Executes
netstat -anoand parses its output, then usestasklistto get process names by PID.
Feel free to submit issues or pull requests for improvements, such as support for additional operating systems or features.
This project is licensed under the MIT License.