GOnetstat

package module
v0.0.0-...-22be0bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2023 License: MIT Imports: 9 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GOnetstat

Netstat implementation in Golang.

This Package get data from /proc/net/tcp|6 and /proc/net/udp|6 and parse /proc/[0-9]/fd/[0-9] to match the correct inode.

Usage

TCP/UDP

tcp_data := GOnetstat.Tcp()
udp_data := GOnetstat.Udp()

This will return a array of a Process struct like this

type Process struct {
    User         string
    Name         string
    Pid          string
    Exe          string
    State        string
    Ip           string
    Port         int64
    ForeignIp    string
    ForeignPort  int64
}

So you can loop through data output and format the output of your program in whatever way you want it. See the Examples folder!

TCP6/UDP6

tcp6_data := GOnetstat.Tcp6()
udp6_data := GOnetstat.Udp6()

The return will be a array of a Process struct like mentioned above. Still need to create a way to compress the ipv6 because is too long.

Documentation

Index

Constants

View Source
const (
	PROC_TCP  = "/proc/net/tcp"
	PROC_UDP  = "/proc/net/udp"
	PROC_TCP6 = "/proc/net/tcp6"
	PROC_UDP6 = "/proc/net/udp6"
)

Variables

View Source
var STATE = map[string]string{
	"01": "ESTABLISHED",
	"02": "SYN_SENT",
	"03": "SYN_RECV",
	"04": "FIN_WAIT1",
	"05": "FIN_WAIT2",
	"06": "TIME_WAIT",
	"07": "CLOSE",
	"08": "CLOSE_WAIT",
	"09": "LAST_ACK",
	"0A": "LISTEN",
	"0B": "CLOSING",
}

Functions

This section is empty.

Types

type Process

type Process struct {
	User        string
	Name        string
	Pid         string
	Exe         string
	State       string
	Ip          string
	Port        int64
	ForeignIp   string
	ForeignPort int64
}

func Tcp

func Tcp(lookupPids bool) ([]Process, error)

func Tcp6

func Tcp6(lookupPids bool) ([]Process, error)

func Udp

func Udp(lookupPids bool) ([]Process, error)

func Udp6

func Udp6(lookupPids bool) ([]Process, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL