Sign in to follow this  
Followers 0
Chimp

how to check if a remote device is SNMP enabled?

8 posts in this topic

#1 ·  Posted (edited)

how can I know if an unknown device that responds to the PING command is SNMP enabled?

Thanks

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites



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 :blink:

.... think there should be a better (and bulletproof  :)) way


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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"
:naughty:  :ranting:, 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: 2017-06-04

Share this post


Link to post
Share on other sites

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.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#8 ·  Posted (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.

#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 by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Kyan
      By Kyan
      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)
       
      TP-Link Manager v0.7.1.zip (v0.7 - 38 downloads)
       
      #Changelog



    • Kyan
      By Kyan
      Sorry for posting this here, the other board is being spam by some jerk so I'm posting this here temporarily
      I'm trying to retrieve a snmp output from my router, I can do it using "snmpwalk 5.7.0" and "MIB Browser", so is not a problem with router configuration. 
      #include "snmp_UDF-v1.7.4.au3" Global $Port = 161 ; UDP 161 = SNMP port Global $SNMP_Version = 2 ; SNMP v2c (1 for SNMP v1) Global $SNMP_Community = "public" ; SNMPString(Community) (change it) Global $SNMP_ReqID = 1 Global $SNMP_Command Global $Start = 1 Global $result Global $Timeout_msec = 2500 UDPStartup() $Socket = UDPOpen('192.168.1.1', $Port) $SNMP_Command = _SNMPBuildPacket('.1.3.6.1.2.1.1.5', $SNMP_Community, $SNMP_Version, $SNMP_ReqID, "A0") UDPSend($Socket, $SNMP_Command) _StartListener() Sleep(200) UDPCloseSocket($Socket) UDPShutdown() Sleep(200) Exit Func _StartListener() If $Start = 1 Then $Timeout = TimerInit() While (1) $srcv = UDPRecv($Socket, 1200) If ($srcv <> "") Then $result = _ShowSNMPReceived($srcv) ConsoleWrite("received: " & $srcv &@LF) ;_ArrayDisplay($result) ExitLoop EndIf Sleep(100) If TimerDiff($Timeout) > $Timeout_msec Then ExitLoop EndIf WEnd EndIf EndFunc ;==>_StartListener Func OnAutoItExit() UDPCloseSocket($Socket) UDPShutdown() EndFunc ;==>OnAutoItExit Request oid: .1.3.6.1.2.1.1.5
      Expected result: TP-LINK
      Received: 0x3082002E02010104067075626C6963A282001F020101020100020100308200123082000E060A2B0001030601020101058000 [ascii: 0‚.public¢‚0‚0‚ +€]
      what am I doing wrong here? There's other cleaner way of doing this, like _snmpGet(server,comunity, oid)?
      thanks for your time
      EDIT: So, there's an output when I use "A1" parameter (but not the correct one), but with A0 I returns 0 or something like that