utils.unix.running module

Parsing and handling process and other run-time information

class utils.unix.running.NetstatSection(*values)

Bases: Enum

Types of ports we might find

NETWORK = 'net'
UNIX = 'unix'
class utils.unix.running.PsMode(*values)

Bases: Enum

Process list modes

AUTO = 'auto'
FLAGS_NONE = 'blank'
FLAGS_f = 'f'
FLAGS_l = 'l'
FLAGS_lf = 'lf'
utils.unix.running.simplify_ifconfig(ifconf_output: str) str

Given an ifconfig output, redacts all the IP addresses and MACs

Replaces them with “X.X.X.X” if they exist

utils.unix.running.simplify_netstat(text: str, section: NetstatSection = NetstatSection.NETWORK, listen_only: bool = False) str

Given the output of a netstat call, returns a table of just the key data

Key data for:

  • Network connections: Proto, Port, and State

  • Unix sockets: Proto, Flags, Type, State, Path

utils.unix.running.simplify_ps(text: str, show_uid: bool = True, mode: PsMode = PsMode.AUTO) str

Given the output of a ps call, returns just non-volatile information

This typically means just the executable name and UID if available.

Works with most ps outputs including ps -A, ps -Al, ps -Af, etc.