https://github.com/intevel/linux-open-ports
📡 Read out all open ports on a linux system
https://github.com/intevel/linux-open-ports
go golang networking networking-in-go portscanner
Last synced: 4 months ago
JSON representation
📡 Read out all open ports on a linux system
- Host: GitHub
- URL: https://github.com/intevel/linux-open-ports
- Owner: Intevel
- License: mit
- Created: 2024-11-10T18:37:16.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-19T00:08:37.000Z (over 1 year ago)
- Last Synced: 2025-10-07T17:51:24.413Z (9 months ago)
- Topics: go, golang, networking, networking-in-go, portscanner
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# linux-open-ports
📡 Go package that retrieves information about open network ports on a Linux system. It identifies active ports and the processes associated with them by reading the system's network connection files in `/proc/net/`.
## Features
- Fetches open TCP and UDP ports.
- Retrieves the PID associated with each open port.
- Supports both IPv4 and IPv6 connections.
- Efficiently handles connections by avoiding duplicates in the port list.
## Installation
To use the `linuxopenports` package, you can add it to your Go project by importing it:
```go
import "github.com/intevel/linux-open-ports"
```
## Usage
The `linuxopenports` package provides a single function, `GetOpenPorts()`, which returns a list of open ports and their associated processes. The function signature is as follows:
```go
func GetOpenPorts() ([]linuxopenports.Port, error)
```
The `GetOpenPorts()` function returns a slice of `Port` structs, each containing the following fields:
```go
type Port struct {
Protocol string // The protocol used by the port (TCP or UDP).
Port uint16 // The port number.
PID int // The process ID associated with the port.
Program string // The name of the program associated with the port.
}
```
Here is an example of how to use the `GetOpenPorts()` function:
```go
package main
import (
"fmt"
"github.com/intevel/linux-open-ports"
)
func main() {
openPorts, err := linuxopenports.GetOpenPorts()
if err != nil {
fmt.Println("Error:", err)
return
}
for _, port := range openPorts {
fmt.Printf("Protocol: %s, Port: %d, PID: %d, Program: %s\n", port.Protocol, port.Port, port.PID, port.Program)
}
}
```
## License
Published under MIT - Made with ❤️ by Conner Bachmann