Skip to content

rromulos/portWatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

PortWatch

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.

Features

  • 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.

Supported Operating Systems

  • Linux: Reads from /proc/net/tcp and /proc/net/udp for connection data.
  • Windows: Uses netstat -ano command to retrieve connection information.
  • Other OS: Displays an "Unsupported operating system" message.

Prerequisites

  • Go 1.16 or later.
  • Dependencies: github.com/fatih/color (automatically installed via go mod).

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/portwatch.git
    cd portwatch
  2. Install dependencies:

    go mod tidy

Usage

Run the application directly:

go run main.go

Or build and run:

go build -o portwatch main.go
./portwatch

Example Output

Proto  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.

How It Works

  • On Linux: Parses /proc/net/tcp and /proc/net/udp files, then maps inodes to PIDs via /proc/*/fd/* and retrieves process names from /proc/*/comm.
  • On Windows: Executes netstat -ano and parses its output, then uses tasklist to get process names by PID.

Contributing

Feel free to submit issues or pull requests for improvements, such as support for additional operating systems or features.

License

This project is licensed under the MIT License.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages