GOnetstat

package module
v0.0.0-...-392ee82 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: MIT Imports: 8 Imported by: 1

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

func CountTcp

func CountTcp() int

func CountTcp6

func CountTcp6() int

func CountTcp6ByPort

func CountTcp6ByPort(port int64) int

func CountTcpByPort

func CountTcpByPort(port int64) int

func CountUdp

func CountUdp() int

func CountUdp6

func CountUdp6() int

func CountUdp6ByPort

func CountUdp6ByPort(port int64) int

func CountUdpByPort

func CountUdpByPort(port int64) int

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 Tcp6ByPort

func Tcp6ByPort(port int64) []Process

func TcpByPort

func TcpByPort(port int64) []Process

func Udp

func Udp() []Process

func Udp6

func Udp6() []Process

func Udp6ByPort

func Udp6ByPort(port int64) []Process

func UdpByPort

func UdpByPort(port int64) []Process

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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