lsof

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseName

func ParseName(node, name string) (net.Addr, net.Addr, error)

ParseName parses `lsof`'s name field, which by default is in the form: [46][protocol][@hostname|hostaddr][:service|port] but we're disabling hostname conversion with the “-n” option and port conversion with the “-P” option, so the output in printed in the more decodable format: “addr:port->addr:port”.

Types

type OpenFile

type OpenFile struct {
	Raw     string
	Command string
	Pid     int
	User    string
	Fd      string
	Type    string
	Device  string
	State   string   // (ENSTABLISHED), (LISTEN), ...
	SrcAddr net.Addr // Source address
	DstAddr net.Addr // Destination address
}

func ParseOpenFile

func ParseOpenFile(line string) (*OpenFile, error)

ParseOpenFile expectes "line" to be a single line output from “lsof -i -n -P” call. The line is unmarshaled into an “OpenFile” only if is splittable by " " into a slice of at least 9 items. "line" should not end with a "\n" delimitator, otherwise it will end up in the last unmarshaled item.

"line" examples: "postgres 676 danielmorandini 10u IPv6 0x25c5bf0997ca88e3 0t0 UDP [::1]:60051->[::1]:60051" "Dropbox 614 danielmorandini 247u IPv4 0x25c5bf09a393d583 0t0 TCP 192.168.0.61:58282->162.125.18.133:https (ESTABLISHED)"

func ParseOutput

func ParseOutput(r io.Reader) ([]OpenFile, error)

ParseOutput expects "r" to contain the output of an “lsof -i -n -P” call. The output is splitted into each new line, and each line that “ParseOpenFile” is able to parse is appended to the final output. Returns an error only if reading from "r" produces an error different from “io.EOF”.

func Run

func Run() ([]OpenFile, error)

Jump to

Keyboard shortcuts

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