Jump to content

Get some MIB information over UDP


enaiman
 Share

Recommended Posts

Again asking for help ...

I'm trying to get some MIB sections over an UDP connection (SNMP).

The port used to connect to a device and to get some information using SNMP is 161. I've found many 3rd party MIB browsers and SNMP software but I would like to avoid using them and I wonder if it is possible to do it using UDP commands in AutoIt.

If some1 have the knowledge and could help me in this matter I would really appreciate it.

Thank you,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

First step, see what we can recive?

#include <GUIConstants.au3>
$IP = "127.0.0.1"

$hwnd = GUICreate ("MIB Data Viewer", 800, 600)
$edit1 = GUICtrlCreateEdit ("", 0, 0, 800, 600)
GUICtrlSetBkColor (-1, 0x000000)
GUICtrlSetColor ($edit1, 0xFFFFFF)
UDPStartup()
$socket = UDPBind($IP, 161)
If @error <> 0 Then Exit

GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg ()
    $data = UDPRecv($socket, 256)
    If $data <> "" Then
        GUICtrlSetData ($edit1, GUICtrlRead ($edit1) & @CRLF & _
        "------------------------------------------------------------------------------------------" & _
        @CRLF & $data)
    EndIf
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc
Link to comment
Share on other sites

It looks like it doesn't work.

Your code exits on

$socket = UDPBind($IP, 161)
If @error <> 0 Then Exit

I've added a couple lines for debugging:

If @error = 1 Then MsgBox(0, "error", "Incorrect IP")
If @error = 2 Then MsgBox(0, "error", "Incorrect port") 
MsgBox(0, "error", @error)

to see what's happening - the error returned was 10049 - so it is not a matter of wrong IP neither a wrong port (my switch IP is 192.168.0.20 and I've modified the script accordingly).

Also tried to send a character to see if I receive something - the same result. I guess I'll have to look for an explanation for SNMP ... dunno if I can find something but I'll try.

Thanks for help Bert,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Link to comment
Share on other sites

@enaiman

This should get you started reading the MIB files :

$objLocator = ObjCreate("WbemScripting.SWbemLocator")
$objServices = $objLocator.connectServer("", "root/snmp/localhost")

$objNamedValueSet= ObjCreate("WbemScripting.SWbemNamedValueSet")

$objNamedValueSet.Add ("AgentAddress", "localhost")
$objNamedValueSet.Add ("AgentReadCommunityName", "public")
$objNamedValueSet.Add ("AgentWriteCommunityName", "private")

$class = "SNMP_RFC1213_MIB_system"

$objSet = $objServices.instancesof( $class,Default,$objNamedValueSet)

for $obj in $objset
    ConsoleWrite ( "-----------------------------" & @CRLF)
    for $prop in $obj.properties_
        ConsoleWrite ( $prop.name & " : " & $prop.value & @CRLF)
    next
next

I hope it does get you going.

If you have found what you are looking for,

please post some example scritps in the Example section of the forum.

This can help some more people when needed.

regards,

ptrex

Link to comment
Share on other sites

If you have found what you are looking for,

please post some example scritps in the Example section of the forum.

This can help some more people when needed.

@ptrex

Thank you very much for your help. Be sure that once I figure out what to do and I'll get a working script I'll post it there.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • 2 months later...

First post here, I'm a MAJOR newbie.

Has anyone created a solution for trapping SNMP in AutoIT? I'm just touching the surface of AutoIT and SNMP, and I need a little direction. I'm trying to create a script that would require a limited user to enter a hostname of a printer (IP Printing) and would then retrieve some basic info about the printer using SNMP (OIDs .1.3.6.1.2.1.1.1.0 [Printer model] and .1.3.6.1.2.1.1.6.0 [Description]) before setting up the printer for the user.

I looked through the sample scripts but didn't find anything that satisfied my need.

Thanks!

Link to comment
Share on other sites

@skewltek

Maybe this can get you going :

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$objLocator = ObjCreate("wbemscripting.swbemlocator")

$objServices = $objLocator.ConnectServer(, "root\snmp\mngd_hub")
$objServices.security_.privileges.AddAsString("SeSecurityPrivilege")
$objSet = $objServices.ExecQuery ("SELECT * FROM SNMP_NET_DEVICE_123 WHERE hdwr_idx>1" , "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

for $obj in $objset
ConsoleWrite( "do whatever ..." & @LF)
Next

;---------------------- SNMP Action ------------------------

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$objLocator = ObjCreate("wbemscripting.swbemlocator")

$objServices = $objLocator.ConnectServer(, "root\snmp\mngd_hub")
$objServices.security_.privileges.AddAsString("SeSecurityPrivilege")
$obj= $objServices.Get("SNMP_NET_DEVICE_123=@")
$obj.deviceLocation = "40/5073"
$obj.put_

It's not showing how to Monitor traps, but you will find examples on the net to do so.

Anyhow this is a link on how to : WMI and SNMP monitoring

Basically you need to map the SNMP TRAPS to the WMI EVENTS in order to get the ball rolling.

Regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

Thanks for your quick reply, ptrex. I think that the problem that I have is that I want user machines to be able to poll SNMP on thier computers, and most of them won't have the WMI SNMP service installed or started on thier machines. If there is not a way I can use the native TCP and/or UDP libraries in AutoIT for this then I will just use a third party command line app to retrieve what I need.

Link to comment
Share on other sites

if you have a commandline tool that can do this.

Let me know which one I might need it too.

There are a couple, one is in a Windows RK, it's called Snmputil.exe and it is pretty simple. Basically:

Snmputil.exe get 10.0.212.2 public .1.3.6.1.2.1.1.6.0

>Variable = system.sysLocation.0
>Value  = String Front Office

The other is in an opensource package from http://www.net-snmp.org/ and it comes with several SNMP monitoring commandline tools. I haven't played with it enough to know what it can do, but it looks pretty extensive.

So are you confirming that AutoIT doesn't have a way built into it that can perform SNMP traps, and that it relies on an outside source (either WMI or a commandline tool like one here) to handle that? I just want to make sure before I spend any more time searching in vain and start researching how to parse commandline output in AutoIT.

Thanks for you're help.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...