Gianni Posted July 19, 2014 Share Posted July 19, 2014 (edited) how can I know if an unknown device that responds to the PING command is SNMP enabled? Thanks Edited July 26, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jguinch Posted July 19, 2014 Share Posted July 19, 2014 Not sure at all, but maybe by checking the connection to the UDP ports 161 and 162 ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Gianni Posted July 19, 2014 Author Share Posted July 19, 2014 Hi jguinch, thanks for answer, just tried to use UDPBind(IP, 161) to a LAN printer that is SNMP enabled, but I get "Could not bind, code: 10049" error. Also tried with UDPOpen(IP, 161) but with this command I always get "Connection successful." even with not pingable or wrong IP addresses .... think there should be a better (and bulletproof ) way Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mLipok Posted July 19, 2014 Share Posted July 19, 2014 Do you check here: http://www.autoitscript.com/wiki/User_Defined_Functions#Internet_protocol_suite and exactly here Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. 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." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Gianni Posted July 19, 2014 Author Share Posted July 19, 2014 Hi mLipok, thanks for the answer already tested that "Reading toner status", but it doesn't run on my system, I get this error: ...wmi_toner_status.au3 (4) : ==> The requested action with this object has failed.: $objWmiServices = $objWmiLocator.ConnectServer("", "rootsnmplocalhost") $objWmiServices = $objWmiLocator.ConnectServer("", "rootsnmplocalhost")^ ERROR anyway, it could be interesting, but I do not know if could be used to just check if a remote device is SNMP enabled. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jguinch Posted July 21, 2014 Share Posted July 21, 2014 Try with rootsnmplocalhost instead of rootsnmplocalhost Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Gianni Posted July 21, 2014 Author Share Posted July 21, 2014 (edited) Try with rootsnmplocalhost instead of rootsnmplocalhost Thanks jguinch, 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 .... Edited July 22, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Gianni Posted July 25, 2014 Author Share Posted July 25, 2014 (edited) 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. expandcollapse popup#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 $line Local $file = FileOpen(".\community.txt", 0) ; open file in read mode If $file <> -1 Then ; Check if file opened for reading OK While 1 ; Read in lines of text until the EOF is reached $line = FileReadLine($file) If @error = -1 Then ExitLoop ReDim $Community[UBound($Community) + 1] $Community[UBound($Community) - 1] = $line WEnd Else ; Error, unable to open file ReDim $Community[UBound($Community) + 1] $Community[1] = "public" EndIf $Community[0] = UBound($Community) - 1 FileClose($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 port Global $SNMP_ReqID = 1 Global $SNMP_Command Global $Result ; set $verbose to True to see snmp calls activity Global $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 = 1 To $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 = 1 To $Community[0] ; try with different community names (if more are available) If Not $verbose Then ConsoleWrite(".") $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 @error Then ; try again with snmp V2 If $verbose Then ConsoleWrite(@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 @error Then If $verbose Then ConsoleWrite(@CRLF & $dest_IP & @TAB & "error: no snmp response with community name " & $SNMP_Community & @TAB & "snmp_V" & $SNMP_Version & @CRLF) Else ConsoleWrite(@CRLF & $dest_IP & @TAB & "community name " & $SNMP_Community & @TAB & "snmp_V" & $SNMP_Version & @TAB & $SNMP_Util[1][1] & @CRLF) ; snmp v2 ExitLoop EndIf Else ConsoleWrite(@CRLF & $dest_IP & @TAB & "community name " & $SNMP_Community & @TAB & "snmp_V" & $SNMP_Version & @TAB & $SNMP_Util[1][1] & @CRLF) ; snmp v1 ExitLoop EndIf Next ; try wit another community name Next ; next IP ConsoleWrite(@CRLF & "end of scan" & @CRLF) Func _StartListener($timeout = 250) Local $Timer = TimerInit(), $error = 1 While TimerDiff($Timer) < $timeout $srcv = UDPRecv($Socket, 2048) If ($srcv <> "") Then $Result = _ShowSNMPReceived($srcv) $error = 0 ; no error, received data before the timeout ExitLoop EndIf Sleep(100) WEnd Return SetError($error) EndFunc ;==>_StartListener Func OnAutoItExit() UDPCloseSocket($Socket) UDPShutdown() EndFunc ;==>OnAutoItExit Edited July 26, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now