enaiman Posted August 29, 2011 Author Posted August 29, 2011 (edited) New Update: 29/08/2011 Thanks to @Shredplayer This update is very useful if you have ever used $SNMP_Received array (declared to have "educational purpose") or if you will work with enterprise-specific OIDs; if you didn't, you won't notice any difference. This UDF works 100% on non-enterprise specific OID's - when it comes to these, some other rules may apply - this is the purpose of this update. Added a new element in $SNMP_Received array - the new element is a string with all PDU's elements delimited by "|" (data type|length|OID|data type|length|util data) This was necessary to offer more flexibility because some enterprise-specific have different decoding rules. Having the raw data in a delimited string will help you "customize" how it is decoded Edited August 29, 2011 by enaiman 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 :)
Shredplayer Posted August 29, 2011 Posted August 29, 2011 Thanks for the update however ive got error using GetBulk 060D2B060104018121130303011A0004818B446967506C61743B31312E5266506C61743B302E426F6172645265763B322E4672657142616E643B312E41646A506F7765723B542E45787452616E67653B462E457874416E743B462E506F6C61723B302E4C6974653B462E4650474153697A653B302E4D6F643B302E504C44576F726B3B462E504C445665723B302E0A4C6F7743757272656E743B542E0A C:\Program Files\AutoIt3\Include\SNMP_UDF_v1.6.au3 (637) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $ArrRet[$idx][0] = $val0 reverted back to 1.5 and No error.
enaiman Posted August 30, 2011 Author Posted August 30, 2011 For some reason - the new forum does not work for me very well - I have no access to the full editor, so I can't delete the attached files to my 1st post. I have fixed the error from last version (1.6) - it was bad array handling - sorry about that. Fixed version number 1.6.1 SNMP_UDF_v1.6.1.au3 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 :)
enaiman Posted November 2, 2011 Author Posted November 2, 2011 New - minor - version update, now 1.6.2 I have added error control for the case when the SNMP querry returned errors - now it will show an error message then exit. Sometime, I might work a little bit on optimization ... 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 :)
enaiman Posted November 7, 2011 Author Posted November 7, 2011 New version: 1.7 Completely rewritten. Not using arrays anymore to handle packets. In the previous code I had a lot of _ArrayAdd, _ArrayDelete and some other and that was slow. Now using strings, it definitely looks much faster now. Because of this massive change, it is highly possible to have some bugs - if you find any, please let me know and I will fix them. 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 :)
ptrex Posted November 7, 2011 Posted November 7, 2011 Hi enaiman,Good to see that you are still maintaining the SNMP UDF !thanksrgdsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
enaiman Posted November 7, 2011 Author Posted November 7, 2011 Hi ptrex, Nice to see you around again I'm trying to make the best out of it; at the moment the code looks a bit messy but I'll fix that in the future ... sometime. 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 :)
SilentButeo2 Posted January 12, 2012 Posted January 12, 2012 I think i found a bug? When calling Func _SNMPBuildPacket($snmpOID, $snmpCOMM = "public", $snmpVER = 1, $snmpReqID = 1, $PDUType = "A1", $GetBulk = "32", $dataTYPE = "05", $dataVALUE = "00") With $dataTYPE = $SNMP_data_INT and $dataValue to 0 or "00", the packet will contain "30" and "3030" at the end. This is the ascii value of the character "0" One would think that it would be "00" that is be added. Another thing i noticed is that when i send the same write snmp with another snmp program, i get different output. The last bytes of the packet your code: 02 00 other program: 02 01 00 the first byte is the type (INTEGER) the third byte is the data it self (0). If the second packet is opened with the sniffer program, the thrid byte is selected as data byte. If i load you packet, when i select the value info, no bytes are selected in the packet. So that way i supose that the packet is incorrect. When I check your code, i think both errors (if these are errors) can be found in the _Build_Varbind() function. One more question. How should one save the write byte in dataVALUE? dataVALUE="1384" dataVALUE="568" dataVALUE=1384 dataVALUE=0x568 kind regards, and thanks for this great UDF!
SilentButeo2 Posted January 12, 2012 Posted January 12, 2012 just check with the other snmp program and if i send there 1384, i get 02 02 05 68 so the first byte is the integer byte the second will contain the number of bytes and de third and fourth will contain the hex value of 1384
enaiman Posted January 12, 2012 Author Posted January 12, 2012 @SilentButeo2 Thank you for taking your time to report this. What are you saying does make sense that the "length" of the data should be there. I didn't notice that because I haven't got any errors so far; but on the other hand, I don't use integers too often. Regarding your second question: the value is always in decimal format. I don't think it does make a difference if using 1384 or "1384". Hex format? - nah, I didn't implement that. Question: did you get any errors or you haven't got an answer back because of the "missing length"? I'll have a look at the uDF and I'll fix that (maybe even today). 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 :)
enaiman Posted January 13, 2012 Author Posted January 13, 2012 New minor update: had to change all StringLen to Int(StringLen) - now it works again (in 3.3.8.0) Couldn't attach the files to first post. snmp_packetgen_write.au3 snmp_packetgen_1.7.1.au3 SNMP_UDF_v1.7.1.au3 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 :)
SilentButeo2 Posted January 13, 2012 Posted January 13, 2012 @enaiman:1. The fix you had to release to work with 3.3.80, is probably a bug in the 3.3.80 version. I opened a bug report for that. (http://www.autoitscript.com/trac/autoit/ticket/2094)2. I adjusted your code to make the INT work. In short i changed next lines:Case $SNMP_data_INT, $SNMP_data_COUNTER, $SNMP_data_GAUGE, $SNMP_data_TIME, $SNMP_data_STR ;(INT, COUNTER, GAUGE, TIME, STR) $p_dVALUE = _StringToHex($p_dVALUE)intoCase $SNMP_data_INT ;(INT) $p_dVALUE =Hex(Int($p_dVALUE), 8) Case $SNMP_data_COUNTER, $SNMP_data_GAUGE, $SNMP_data_TIME, $SNMP_data_STR ;(COUNTER, GAUGE, TIME, STR) $p_dVALUE = _StringToHex($p_dVALUE)Now the output is correct if I view the created packet in WireShark. The correct data length is filled (thanks) and the correct data is added.Optimizations could be done.- Only add the number of bytes that are needed. Now there are always 4 bytes added- don't know if the fix for INTEGERS should also be done for COUNTER, GAUGE, TIME?Other smaller fixes i had to do to run without warnings/errors.AddAutoItSetOption ( "MustDeclareVars", 1 )at the beginning of your file to check these warnings/errors.Added my patched UDF file as a reference.SNMP_UDF_testing.au3
SilentButeo2 Posted January 13, 2012 Posted January 13, 2012 Just see that it is you that replied to my bug .
enaiman Posted January 15, 2012 Author Posted January 15, 2012 (edited) Thanks again for pointing out this behaviour. I'll fix the UDF as soon as possible; definitely: gauge, counter, time and Int needs to be converted not as strings but as numbers. EDIT: Fixed the INT behaviour; I've decided to use 8 digits for conversion then strip pairs of 0 from the left. Edited January 16, 2012 by enaiman 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 :)
enaiman Posted January 16, 2012 Author Posted January 16, 2012 Again the full editor is playing tricks on me. Here are the updated files: SNMP_UDF_v1.7.2.au3 snmp_packetgen_1.7.2.au3 snmp_packetgen_write.au3 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 :)
zEwt Posted January 16, 2012 Posted January 16, 2012 (edited) big thanks on this UDF... now i would like to create a desktop version of what i have already done php. i just need to send an snmp trap ... anyone have an example of this using this UDF? greatly appreciate it. i see i can read packets with SNMPBuildPacket... but can i generate a SNMP packet and send it to a backend server? here is my config with OID's. $source_ip= "xx.xx.xx.xx"; $dest_Address = "xx.xx.xx.xx"; $enterprise="1.3.6.1.4.1.13568"; $GenericType=6; $SpecificType=3; $OID1="1.3.6.1.4.1.13568.1.0"; $OID2="1.3.6.1.4.1.13568.2.0"; $OID3="1.3.6.1.4.1.13568.3.0"; $OID4="1.3.6.1.4.1.13568.4.0"; $OID5="1.3.6.1.4.1.13568.5.0"; $OID6="1.3.6.1.4.1.13568.6.0"; $OID7="1.3.6.1.4.1.13568.7.0"; and here is how i am currently sending trap via PHP on my Linux/Apache build. just uses sendtrap command... exec("/opt/EMPsysedge/bin/sendtrap -v 1 -f ".$source_ip." -h ".$dest_Address." -c public ".$enterprise." ".$GenericType." ".$SpecificType." ".$OID1." -s ".'"'.$email.'"'." ".$OID2." -s ".'"'.$filter.'"'." ".$OID3." -s ".'"'.$startTime.'"'." ".$OID4." -s ".'"'.$endTime.'"'." ".$OID5." -s ".strtoupper($_POST['actionType'])." ".$OID6." -s ".'"'.$_SESSION['SERVICE'].'"'." ".$OID7." -s ".'"'.$reason.'"'); Edited January 16, 2012 by zEwt
SilentButeo2 Posted January 16, 2012 Posted January 16, 2012 something like this? UDPStartUp() $socket = UDPopen($dest_IP, $dest_Port) $SNMP_Command = _SNMPBuildPacket( $your_snmp_settings ) UDPSend($socket, $SNMP_Command)
enaiman Posted January 16, 2012 Author Posted January 16, 2012 @zEwt I'm afraid you're out of luck here. My UDF can't build trap packets because the packet format is different. I was thinking at some point to add that functionality but haven't got the time to do it. I will definitely add that at some point but I can't promise anything; might be months or more. The most difficult part of this is getting the packet structure and the algorythm to use to build the packet - it does require a fair bit of research and testing and my time is quite limited. 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 :)
joecoolgee Posted March 20, 2012 Posted March 20, 2012 Good day.. I'd like to start by saying, im new to AutoIt and last programming i did was C++ about 10 years ago... trying to shake the rust off and its not getting any better... I've made a couple of small programs to get started and need to tackle SNMP sets and gets... Currently I use NET-SNMP and use Shellexecute() to set OIDs in a Cisco switch... I'd love to implement a simple set or get via your UDF but am having a really hard time getting any of the functions to work, even the generic one snmp_packetgen_write.au3 The only value I changed was $dest_IP to that of the switch and I get stuck with a bunch of hex at the bottom of the page... any help would be appreciated!!! expandcollapse popup#Include <String.au3> #Include <Array.au3> #Include 'SNMP_UDF_v1.7.2.au3' ; ----- CAUTION ------------------------------------------------------------- ; This script will modify the value found at sysLocation (1.3.6.1.2.1.1.6.0) ; it is your job to write back whatever was there previously :) ;---------------------------------------------------------------------------- ;In order to have a succesful script run you will need to be sure that: ; - you are using the "write" community string ; - the OID where you want to write is NOT Read-Only ; - the value type you want to write is according to that OID (if you try to write text in an integer type OID it will fail) Global $dest_IP = "192.168.1.2" ; Destination Address (change it) Global $Port = 161 ; UDP 161 = SNMP port Global $SNMP_Version = 2 ; SNMP v2c (1 for SNMP v1) Global $SNMP_Community = "private" ; SNMPString(Community) - you need the "write" community string to test this. Global $SNMP_ReqID = 1 Global $SNMP_Command Global $Start = 1 Global $result UDPStartUp() $Socket = UDPopen($dest_IP, $Port) ;Read value at sysLocation Global $SNMP_OID = "1.3.6.1.2.1.1.6.0" $SNMP_Command = _SNMPBuildPacket($SNMP_OID, $SNMP_Community,$SNMP_Version, $SNMP_ReqID, "A0") UDPSend($Socket, $SNMP_Command) _StartListener() sleep (200) _ArrayDisplay($SNMP_Util, "GetRequest 1x OID") ;Write value at sysLocation Global $SNMP_OID = "1.3.6.1.2.1.1.6.0" $SNMP_Command = _SNMPBuildPacket($SNMP_OID, $SNMP_Community,$SNMP_Version, $SNMP_ReqID, "A3", "32", "04", "My_TEST") UDPSend($Socket, $SNMP_Command) _StartListener() sleep (200) _ArrayDisplay($SNMP_Util, "Write 1x OID") ;Read new value at sysLocation Global $SNMP_OID = "1.3.6.1.2.1.1.6.0" $SNMP_Command = _SNMPBuildPacket($SNMP_OID, $SNMP_Community,$SNMP_Version, $SNMP_ReqID, "A0") UDPSend($Socket, $SNMP_Command) _StartListener() sleep (200) _ArrayDisplay($SNMP_Util, "GetRequest 1x OID") Func _StartListener() If $Start = 1 Then $i = 0 While (1) $srcv = UDPRecv($Socket, 2048) If ($srcv <> "") Then $result = _ShowSNMPReceived ($srcv) ConsoleWrite($srcv &@CRLF) ;_ArrayDisplay($result) ExitLoop EndIf sleep(100) WEnd EndIf EndFunc Func OnAutoItExit() UDPCloseSocket($Socket) UDPShutdown() EndFunc
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