device

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: GPL-3.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// OS is the local machine's Operating System type.
	OS = Linux

	// Shell is the default machine specific command shell.
	Shell = "/bin/bash"
	// Newline is the machine specific newline character.
	Newline = "\n"
)
View Source
const (
	// IDSize is the amount of bytes used to store the Host ID and
	// SessionID values.  The ID is the (HostID + SessionID).
	IDSize = 32
	// MachineIDSize is the amount of bytes that is used as the Host
	// specific ID value that does not change when on the same host.
	MachineIDSize = 28
)
View Source
const (
	// Windows represents the Windows family of Operating Systems.
	Windows deviceOS = 0x0
	// Linux represents the Linux family of Operating Systems
	Linux deviceOS = 0x1
	// Unix represents the Unix family of Operating Systems
	Unix deviceOS = 0x2
	// Mac represents the MacOS/BSD family of Operating Systems
	Mac deviceOS = 0x3

	// Arch64 represents the 64-bit chipset family.
	Arch64 deviceArch = 0x0
	// Arch86 represents the 32-bit chipset family.
	Arch86 deviceArch = 0x1
	// ArchARM represents the ARM chipset family.
	ArchARM deviceArch = 0x2
	// ArchPowerPC represents the PowerPC chipset family.
	ArchPowerPC deviceArch = 0x3
	// ArchMips represents the MIPS chipset family.
	ArchMips deviceArch = 0x4
	// ArchUnknown represents an unknown chipset family.
	ArchUnknown deviceArch = 0x5
)
View Source
const IPv6 = true

IPv6 is a compile-time flag that enables (true) or disables (false) support for IPv6-based network addresses.

Variables

View Source
var (
	// UUID is the device specific and session specific identifier.
	UUID = getID()

	// Arch is the local machine's Architecture type.
	Arch = getArch()

	// Version is the local machine's Operating System version information.
	Version = getVersion()

	// Environment is a mapping of environment string names to their string values.
	Environment = getEnv()
)
View Source
var Local = (&local{&Machine{
	ID:       UUID,
	OS:       OS,
	PID:      uint32(os.Getpid()),
	PPID:     uint32(os.Getppid()),
	Arch:     Arch,
	User:     "Unknown",
	Version:  Version,
	Network:  make(Network, 0),
	Hostname: "Unknown",
	Elevated: isElevated(),
}}).init()

Local is the pointer to the local machine instance. This instance is loaded at runtime and is used for local data gathering.

View Source
var ShellArgs = []string{"-c"}

ShellArgs is the default machine specific command shell arguments to run commands.

Functions

func Elevated

func Elevated() bool

Elevated returns the local machine's Elevated running status.

func Expand

func Expand(s string) string

Expand attempts to determine environment variables from the current session and translate them from the supplied string. This function supports both Windows (%var%) and *nix ($var or ${var}) variable substitutions.

func Hostname

func Hostname() string

Hostname returns the local machine's Hostname value.

func PID

func PID() uint32

PID returns the local machine's PID value.

func PPID

func PPID() uint32

PPID returns the local machine's Parent PID value.

func User

func User() string

User returns the local machine's current running Username.

Types

type ID

type ID [IDSize]byte

ID is an alias for a byte array that represents a 32 byte client identification number. This is used for tracking and detection purposes. The first byte and the machine ID byte should NEVER be zero, otherwise it signals an invalid ID value or missing a random identifier.

func (ID) Empty

func (i ID) Empty() bool

Empty returns true if this ID is considered empty.

func (ID) Equal

func (i ID) Equal(a ID) bool

Equal will return true if both ID values are equal in size and have the same Hash value.

func (ID) FullString

func (i ID) FullString() string

FullString returns the full string representation of this ID instance.

func (ID) Hash

func (i ID) Hash() uint32

Hash returns the 32bit hash sum of this ID value. The hash mechanism used is similar to the hash/fnv mechanism.

func (ID) Load

func (i ID) Load(s string) error

Load will attempt to load the Session UUID from the specified file. This function will return an error if the file cannot be read or not found.

func (ID) MarshalStream

func (i ID) MarshalStream(w data.Writer) error

MarshalStream transform this struct into a binary format and writes to the supplied data.Writer.

func (*ID) Read

func (i *ID) Read(r io.Reader) error

Read will attempt to read up to 'IDSize' bytes from the reader into this ID.

func (ID) Save

func (i ID) Save(s string) error

Save will attempt to save the Session UUID to the specified file. This function will return an error if the file cannot be written to or created.

func (*ID) Seed

func (i *ID) Seed(b []byte)

Seed will set the random portion of the ID value to the specified byte array value.

func (ID) Signature

func (i ID) Signature() string

Signature returns the signature portion of the ID value. This value is constant and unique for each device.

func (ID) String

func (i ID) String() string

String returns a representation of this ID instance.

func (*ID) UnmarshalStream

func (i *ID) UnmarshalStream(r data.Reader) error

UnmarshalStream transforms this struct from a binary format that is read from the supplied data.Reader.

func (ID) Write

func (i ID) Write(w io.Writer) error

Write will attempt to write the ID bytes into the supplied writer.

type Machine

type Machine struct {
	User     string `json:"user"`
	Version  string `json:"version"`
	Hostname string `json:"hostname"`

	Network Network `json:"network"`

	PID  uint32 `json:"pid"`
	PPID uint32 `json:"ppid"`

	ID       ID         `json:"id"`
	Arch     deviceArch `json:"arch"`
	OS       deviceOS   `json:"os"`
	Elevated bool       `json:"elevated"`
}

Machine is a struct that contains information about a specific device. This struct contains generic Operating System Information such as Version, Arch and network information.

func (Machine) MarshalStream

func (m Machine) MarshalStream(w data.Writer) error

MarshalStream transforms this struct into a binary format and writes to the supplied data.Writer.

func (Machine) String

func (m Machine) String() string

String returns a simple string representation of the Machine instance.

func (*Machine) UnmarshalStream

func (m *Machine) UnmarshalStream(r data.Reader) error

UnmarshalStream transforms this struct from a binary format that is read from the supplied data.Reader.

type Network

type Network []device

Network is a basic listing of network interfaces. Used to store and refresh interface lists.

func Net

func Net() Network

Net returns the local machine's Network data.

func (Network) Len

func (n Network) Len() int

Len returns the number of detected interfaces detected.

func (Network) MarshalStream

func (n Network) MarshalStream(w data.Writer) error

MarshalStream writes the data of this Network to the supplied Writer.

func (*Network) Refresh

func (n *Network) Refresh() error

Refresh collects the interfaces connected to this system and fills this Network object with the information. If previous Network information is contained in this Network object, it is cleared before filling.

func (*Network) UnmarshalStream

func (n *Network) UnmarshalStream(r data.Reader) error

UnmarshalStream reads the data of this Network from the supplied Reader.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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