gonetstat

package module
v0.0.0-...-3ffd4d1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 8 Imported by: 0

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() []Process

func Tcp6

func Tcp6() []Process

func Udp

func Udp() []Process

func Udp6

func Udp6() []Process

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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