I've recently been looking at the old SNMP UDP, and although it has served well over a long period of time it did look in need of a freshen up.
So from the ground up, reintroducing SNMPv2.
The UDF is still only community string stuff, so just SNMPv1 and SNMPv2c for now.
V3 support is probably a ways off I'm affraid - the projects only about a week old, and theres a ton of work to be done before attacking that.
The basic workflow is:
Call the startup func
Register a function to recieve incoming messages. (basically to recieve decoded OID/Value pairs.)
or if you cant be bothered, an internal one will just write to the console!
Open a device
start querying devices and stuff
The zip file attached has a bunch of demos scripts etc. to get you going.
But here's an example script for post #1 anyhow.
#include "SNMPv2.au3"
;--------------------------------------------------
Local $sIPAddress = "10.0.0.5" ;Device
$__g_bRetTicksAsStr = True ;Return TimeTicks as human readable string (instead of int)
;There are few global params for now that you can set. - Check the demo scripts for details.
;--------------------------------------------------
Global Const $sOID_sysDescr = "1.3.6.1.2.1.1.1.0"
Global Const $sOID_sysName = "1.3.6.1.2.1.1.5.0"
Global Const $sOID_sysLocation = "1.3.6.1.2.1.1.6.0"
Global Const $sOID_sysUpTime = "1.3.6.1.2.1.1.3.0"
Global $mOIDLabMap[]
$mOIDLabMap[$sOID_sysDescr] = "sysDescr"
$mOIDLabMap[$sOID_sysName] = "sysName"
$mOIDLabMap[$sOID_sysLocation] = "sysLocation"
$mOIDLabMap[$sOID_sysUpTime] = "sysUpTime"
; Startup and register a handler for incoming messages.
; The function must accept 4 parameters - more on this futher down
_SNMP_Startup("_CustomMsgHandler")
;Open device
Local $iDevice = _SNMP_OpenDevice($sIPAddress)
;Get one specfic property.
;The community param is optional. (defaults to "public")
_SNMP_GetRequest($iDevice, $sOID_sysDescr, "public")
;Or get multiple properties in one request.
Local $aOids[3]
$aOids[0] = $sOID_sysName
$aOids[1] = $sOID_sysLocation
$aOids[2] = $sOID_sysUpTime
_SNMP_GetRequest($iDevice, $aOids)
;Temporarily keep the script alive!
Sleep(500)
;Cleanup
_SNMP_CloseDevice($iDevice)
_SNMP_Shutdown()
; Handler Params:
; $iDevice - device that responded
; $dPacket - rawData
; $avHeader - metadata pulled from the response. Format: $array[6][2] (field, data)
; $avVarBinds - list of OID's and their associated data. Format: $array[n][6] (OID, Type, Value, RawType, RawValue)
; header feilds - "SNMP Version", "Community", "Request Index", "Error Message", "Error Code", "Error Index"
Func _CustomMsgHandler($iDevice, $dRawPacket, $avHeaders, $avVarBinds)
Local $sFeild, $vData
For $i = 0 To UBound($avVarBinds) - 1
; $avVarBinds[index][OID, Type, Value, RawType, RawValue]
$sFeild = $mOIDLabMap[$avVarBinds[$i][0]]
$vData = $avVarBinds[$i][2]
ConsoleWrite(StringFormat("%15s: %s\r\n", $sFeild, $vData))
Next
EndFunc
SNMPv2c_1.0.zip