procspy

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2018 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package procspy lists TCP connections, and optionally tries to find the owning processes. Works on Linux (via /proc) and Darwin (via `lsof -i` and `netstat`). You'll need root to use Processes().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadNetnsFromPID added in v1.4.0

func ReadNetnsFromPID(pid int) (uint64, error)

ReadNetnsFromPID gets the netns inode of the specified pid

func ReadTCPFiles added in v1.4.0

func ReadTCPFiles(pid int, buf *bytes.Buffer) (int64, error)

ReadTCPFiles reads the proc files tcp and tcp6 for a pid

Types

type ConnIter

type ConnIter interface {
	Next() *Connection
}

ConnIter is returned by Connections().

type Connection

type Connection struct {
	Transport     string
	LocalAddress  net.IP
	LocalPort     uint16
	RemoteAddress net.IP
	RemotePort    uint16
	Inode         uint64
	Proc          Proc
}

Connection is a (TCP) connection. The Proc struct might not be filled in.

type ConnectionScanner added in v0.13.0

type ConnectionScanner interface {
	// Connections returns all established (TCP) connections.
	Connections() (ConnIter, error)
	// Stops the scanning
	Stop()
}

ConnectionScanner scans the system for established (TCP) connections

func NewConnectionScanner added in v0.13.0

func NewConnectionScanner(walker process.Walker, processes bool) ConnectionScanner

NewConnectionScanner creates a new Linux ConnectionScanner

func NewSyncConnectionScanner added in v1.3.0

func NewSyncConnectionScanner(walker process.Walker, processes bool) ConnectionScanner

NewSyncConnectionScanner creates a new synchronous Linux ConnectionScanner

type FixedScanner added in v0.13.0

type FixedScanner []Connection

FixedScanner implements ConnectionScanner and uses constant Connection and ConnectionProcs.

func (FixedScanner) Connections added in v0.13.0

func (s FixedScanner) Connections() (ConnIter, error)

Connections implements ConnectionsScanner.Connections

func (FixedScanner) Stop added in v0.13.0

func (s FixedScanner) Stop()

Stop implements ConnectionsScanner.Stop (dummy since there is no background work)

type Proc

type Proc struct {
	PID            uint
	Name           string
	NetNamespaceID uint64
}

Proc is a single process with PID and process name.

type ProcNet

type ProcNet struct {
	// contains filtered or unexported fields
}

ProcNet is an iterator to parse /proc/net/tcp{,6} files.

func NewProcNet

func NewProcNet(b []byte) *ProcNet

NewProcNet gives a new ProcNet parser.

func (*ProcNet) Next

func (p *ProcNet) Next() *Connection

Next returns the next connection. All buffers are re-used, so if you want to keep the IPs you have to copy them.

Jump to

Keyboard shortcuts

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