Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Share this post

Link to post

Share on other sites

with your suggested syntax the above script now works, so now I can elaborate on it.

anyway, despite to that topic title ">Reading toner status from SNMP device" it seems instead that the script by ptrex show various of the device properties but the toner level. Also seems indeed that the posts on that topic are discussing about another script of that one in the first post. However it's an interesting script that shows how to use SNMP via WMI.

I'm still searching an easy way on how to check if a network device is enabled to SNMP ....

Share this post

Link to post

Share on other sites

according to what stated here, what I am in search of, should be an "SNMP Ping"

following the answer suggested here and taking this as example, I come out with this draft that first will scan your entire LAN for any IP device and then will try to get an snmp response from all the IP devices found alive . If an snmp response is returned, it is printed by ConsoleWrite().

Any improvements are welcome.

#include <multiping.au3>; <- download this from here: http://www.autoitscript.com/forum/topic/156395-versatile-multi-ping#include <snmp_UDF-v1.7.4.au3>; <- download this from here: http://www.autoitscript.com/forum/topic/81687-snmp-udf-for-snmpv1-and-snmpv2c; #include <array.au3>Global$Community[1]; ------------------------------------------; read community names from file if it exists; ------------------------------------------Local$lineLocal$file=FileOpen(".\community.txt",0); open file in read modeIf$file<>-1Then; Check if file opened for reading OKWhile1; Read in lines of text until the EOF is reached$line=FileReadLine($file)If@error=-1ThenExitLoopReDim$Community[UBound($Community)+1]$Community[UBound($Community)-1]=$lineWEndElse; Error, unable to open fileReDim$Community[UBound($Community)+1]$Community[1]="public"EndIf$Community[0]=UBound($Community)-1FileClose($file); -------------------------------------; discover all IP devices in local LAN; and populate the $ipResults array; -------------------------------------ConsoleWrite(@CRLF&"searching all IP devices"&@CRLF)Local$ipResults=_nPing()ConsoleWrite("Found "&$ipResults[0][0]&" devices alive"&@CRLF); _ArrayDisplay($ipResults)Global$Port=161; UDP 161 = SNMP portGlobal$SNMP_ReqID=1Global$SNMP_CommandGlobal$Result; set $verbose to True to see snmp calls activityGlobal$verbose=False; output to consolewrite only devices responding to the snmp call; -------------------------------; search for snmp enabled devices; -------------------------------UDPStartup()ConsoleWrite("now searching for snmp enabled devices"&@CRLF)For$i=1To$ipResults[0][0]; check for snmp on all IP devices$dest_IP=$ipResults[$i][0]$Socket=UDPOpen($dest_IP,$Port)Global$SNMP_OID="1.3.6.1.2.1.1.1.0"; ask to the device "What is your name?"For$ii=1To$Community[0]; try with different community names (if more are available)IfNot$verboseThenConsoleWrite(".")$SNMP_Community=$Community[$ii]$SNMP_Version=1$SNMP_Command=_SNMPBuildPacket($SNMP_OID,$SNMP_Community,$SNMP_Version,$SNMP_ReqID,"A0")UDPSend($Socket,$SNMP_Command)_StartListener()If@errorThen; try again with snmp V2If$verboseThenConsoleWrite(@CRLF&$dest_IP&@TAB&"error: no snmp response with community name "&$SNMP_Community&@TAB&"snmp_V"&$SNMP_Version&@CRLF)$SNMP_Version=2$SNMP_Command=_SNMPBuildPacket($SNMP_OID,$SNMP_Community,$SNMP_Version,$SNMP_ReqID,"A0")UDPSend($Socket,$SNMP_Command)_StartListener()If@errorThenIf$verboseThenConsoleWrite(@CRLF&$dest_IP&@TAB&"error: no snmp response with community name "&$SNMP_Community&@TAB&"snmp_V"&$SNMP_Version&@CRLF)ElseConsoleWrite(@CRLF&$dest_IP&@TAB&"community name "&$SNMP_Community&@TAB&"snmp_V"&$SNMP_Version&@TAB&$SNMP_Util[1][1]&@CRLF); snmp v2ExitLoopEndIfElseConsoleWrite(@CRLF&$dest_IP&@TAB&"community name "&$SNMP_Community&@TAB&"snmp_V"&$SNMP_Version&@TAB&$SNMP_Util[1][1]&@CRLF); snmp v1ExitLoopEndIfNext; try wit another community nameNext; next IPConsoleWrite(@CRLF&"end of scan"&@CRLF)Func_StartListener($timeout=250)Local$Timer=TimerInit(),$error=1WhileTimerDiff($Timer)<$timeout$srcv=UDPRecv($Socket,2048)If($srcv<>"")Then$Result=_ShowSNMPReceived($srcv)$error=0; no error, received data before the timeoutExitLoopEndIfSleep(100)WEndReturnSetError($error)EndFunc;==>_StartListenerFunc OnAutoItExit()UDPCloseSocket($Socket)UDPShutdown()EndFunc;==>OnAutoItExit

Sign in

Similar Content

Hello!
Been working on this, SNMP UDF is a bit incomplete, but found a way to make it work as I wanted.

Features
Restarts wan connection
Retrieve connected devices (Local IP/MAC address/device name)
Displays: router external ip | up time | brand & model
I made this for my home router, but probably works on others models and brands (except the restart function, that is a TP-LINK exclusive xD)