snmp

package
v0.0.148 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package snmp provides shared SNMP protocol helpers used by both discover and enumerate modules.

Index

Constants

This section is empty.

Variables

View Source
var CommonNoAuthUsernames = []string{
	"public",
	"initial",
	"admin",
	"snmpuser",
	"default",
	"monitor",
	"noauth",
	"",
}

CommonNoAuthUsernames are the default usernames tested for NoAuthNoPriv access.

View Source
var SystemOIDs = []string{
	"1.3.6.1.2.1.1.1.0",
	"1.3.6.1.2.1.1.2.0",
	"1.3.6.1.2.1.1.3.0",
	"1.3.6.1.2.1.1.4.0",
	"1.3.6.1.2.1.1.5.0",
	"1.3.6.1.2.1.1.6.0",
	"1.3.6.1.2.1.1.7.0",
}

SystemOIDs are the standard system MIB OIDs queried by SNMP operations.

Functions

func ExtractStringValue

func ExtractStringValue(value interface{}) string

ExtractStringValue converts various SNMP value types to string. Returns empty string for nil values to avoid "<nil>" literals.

func FormatUptime

func FormatUptime(seconds int) string

FormatUptime converts seconds to a human-readable format.

func LookupEnterpriseName

func LookupEnterpriseName(enterpriseID int) string

LookupEnterpriseName returns the enterprise name for a given enterprise ID.

func ParseEngineID

func ParseEngineID(engineID []byte) (format, data string, enterprise int)

ParseEngineID analyzes the engine ID format and extracts relevant information.

func PopulateServerInfo

func PopulateServerInfo(serverInfo *commonprotocolfern.SnmpServerInfo, v3Info *SNMPv3EngineInfo, sysInfo *SNMPSystemInfo)

PopulateServerInfo fills a SnmpServerInfo from SNMPv3EngineInfo and SNMPSystemInfo.

Types

type SNMPSystemInfo

type SNMPSystemInfo struct {
	SysDescr    string
	SysObjectID string
	SysUpTime   uint32
	SysContact  string
	SysName     string
	SysLocation string
	SysServices int
}

SNMPSystemInfo holds SNMP system MIB information.

func ParseSystemInfo

func ParseSystemInfo(result *gosnmp.SnmpPacket) *SNMPSystemInfo

ParseSystemInfo extracts system MIB values from an SNMP GET result.

func TrySNMPCommunityCheck

func TrySNMPCommunityCheck(ip net.IP, port uint16, timeout int, community string, version gosnmp.SnmpVersion) (bool, *SNMPSystemInfo, error)

TrySNMPCommunityCheck tests if an SNMP community string works. Returns success status, system info, and error.

func TrySNMPv3NoAuthGet

func TrySNMPv3NoAuthGet(ip net.IP, port uint16, username string) (bool, *SNMPSystemInfo)

TrySNMPv3NoAuthGet attempts a single SNMPv3 GET with NoAuthNoPriv for a specific username. Returns true if the GET succeeds (unauthenticated read access is allowed). Also returns parsed system info if the query succeeded.

type SNMPv3EngineInfo

type SNMPv3EngineInfo struct {
	EngineID       string
	EngineIDFormat string
	EngineIDData   string
	EngineBoots    int
	EngineTime     int
	Enterprise     int
}

SNMPv3EngineInfo holds SNMPv3 engine discovery information.

func TrySNMPv3Discovery

func TrySNMPv3Discovery(ip net.IP, port uint16, timeout int) (*SNMPv3EngineInfo, string, error)

TrySNMPv3Discovery attempts SNMPv3 engine discovery. Returns engine info, system description (if available), and error.

Jump to

Keyboard shortcuts

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