SNMP SetRequest / Send UDP Bitstream


#1

Is it possible to use the SNAP-PAC-R2 to send a SNMP SetRequest packet to an external SNMP device? It seems like it would be similar to sending a cold start trap but with different data. If that’s not possible, is it possible to send a specific bit/hex string using UDP? I used wireshark and GetIf to sniff the exact bit sequence that has to be sent. Unfortunately, the stream contains 0x00, which is equivalent to an ascii NULL, so typing the ascii string equivalent is not possible.


#2

Hello John I,

Welcome to the OptoForums!

Could you give us a bigger-picture view of what you’re trying to do here? Usually SNMP is not the easiest way to do it, perhaps there’s another way. FYI, be sure to check out this [B][U]SNMP 101 post[/U][/B], and perhaps also [B][U][URL=“http://www.opto22.com/community/showthread.php?t=170”]this SNMP discussion[/U][/B] which includes some sample OptoScript code/charts. Note that the second discussion I mentioned there includes 2 pages and the 1st reply on the last page is from someone claiming to have done something similar to what you’re trying to do there. You might post a reply to that thread and ask for details.

However, since you mentioned Wireshark and rolling your own UDP packet (fun stuff!), I’d also like to address your comment about typing an ASCII 0x00. You can still build a string in PAC Control with whatever binary values you want in it (I do it all the time, often to re-create packets I’ve sniffed in Wireshark). In OptoScript, it’d just look something like this:

MyString = "hello" + chr(0);

Or in an Action Block, you can use the String command “Append Character to String” where the character you’re appending would be a zero. (The help on that command also gives the OptoScript equivalent.)

BTW, although we don’t quite yet “officially” support UDP in comm handles, it’s just a matter of documenting it and lots of folks are using it all the time. [B][U]Check out this post on udp for details[/U][/B].

Hope that helps. I hope you’ll report back on how do did (or share code! we love shared code!)

Sincerely,
OptoMary


#3

Hello Mary,

Thanks for taking the time to respond!

I’m trying to use the SNAP-PAC-R2 to remotely turn an outlet on and off on a power strip. The outlet states can be controlled via SNMP and I have verified this using the MIB browser Getif. If there is a way to send an SNMP message based on an OID # using OPTO gear, please let me know. I have read through the links you have posted but they mostly concern receiving an ascii string or sending a trap that contains an ascii string.

Assuming I can’t simply send a SetRequest SNMP packet with an OID, I hope to recreate the exact bit string and send that instead. However, when I sniffed the SNMP packet from Getif, the hex data contained …“30 82 00 37 02 01 00 04”… which corresponded to …"…"… on the ascii side, because those hex values don’t correspond to normal ascii characters (http://www.asciitable.com/). Therefore, I am unable to simply reverse the process and send an ascii string that corresponds to the desired hex string. Is there some way to explicitly define the bit string to be sent by UDP instead of just ascii characters?

As for an alternative to SNMP, the PDU does accept serial communication but it requires pressing the escape button to navigate the menu. I am definitely open to any suggestions.

Thanks again for your help,
John


#4

Yes. Usually the tricky part is figuring out exactly what that magic packet should be. But since you already have that hex data, you’re most of the way there. Here’s some code I wrote for a similar experiment using OptoScript:


/* UDP Stream from Wireshark for SET command, last byte is the data:

00000000  30 31 02 01 00 04 06 70  75 62 6c 69 63 a3 24 02 01.....p ublic.$.
00000010  04 7a fc c0 39 02 01 00  02 01 00 30 16 30 14 06 .z..9... ...0.0..
00000020  0f 2b 06 01 04 01 a2 79  06 01 07 01 01 01 02 00 .+.....y ........
00000030  02 01 16       

*/
sSNMPset = chr(0x30) + chr( 0x31 ) + chr(0x02) + chr( 0x01 ) + chr(0x00) + chr( 0x04 ) + chr(0x06) + chr( 0x70 ) +  chr(0x75) + chr( 0x62 ) + chr(0x6c) + chr( 0x69 ) + chr(0x63) + chr( 0xa3 ) + chr(0x24) + chr( 0x02 ) + 
chr(0x04) + chr( 0x7a ) + chr(0xfc) + chr( 0xc0 ) + chr(0x39) + chr( 0x02 ) + chr(0x01) + chr( 0x00 ) + chr(0x02) + chr( 0x01 ) + chr(0x00) + chr( 0x30 ) + chr(0x16) + chr( 0x30 ) + chr(0x14) + chr( 0x06 ) + 
chr(0x0f) + chr( 0x2b ) + chr(0x06) + chr( 0x01 ) + chr(0x04) + chr( 0x01 ) + chr(0xa2) + chr( 0x79 ) + chr(0x06) + chr( 0x01 ) + chr(0x07) + chr( 0x01 ) + chr(0x01) + chr( 0x01 ) + chr(0x02) + chr( 0x00 ) + 
chr(0x02) + chr( 0x01 ) + chr(nYourNumberHere);      


SetCommunicationHandleValue("udp:10.192.57.39:161", chUDP);

nUDPStatus = OpenOutgoingCommunication( chUDP );

Of course, this is not very pretty, but it sounds like you’ll just be sending perhaps a 0 or one on that last byte (where I had [B]nYourNumberHere[/B]), so perhaps not too horrible.

The next command you’d use after this would be: TransmitString to send out sSNMPSet. You could then do a close. (Or Receive if you’re feeling really adventurous and want to try to parse the reply that comes back…)

-OptoMary

p.s. I used my favorite little free editor, Notepad++ to edit that info from Wireshark, e.g. 30 82… I deleted the left columns and right columns (hold down Alt to highlight columns). I also recorded a Notepad++ macro to add the extra OptoScript syntax like “chr(0x” to save myself some typing.

Write a macro to write your OptoScript, and enjoy more of your weekend!


#5

Yes. Usually the tricky part is figuring out exactly what that magic packet should be. But since you already have that hex data, you’re most of the way there. Here’s some code I wrote for a similar experiment using OptoScript:

/* UDP Stream from Wireshark for SET command, last byte is the data:

00000000  30 31 02 01 00 04 06 70  75 62 6c 69 63 a3 24 02 01.....p ublic.$.
00000010  04 7a fc c0 39 02 01 00  02 01 00 30 16 30 14 06 .z..9... ...0.0..
00000020  0f 2b 06 01 04 01 a2 79  06 01 07 01 01 01 02 00 .+.....y ........
00000030  02 01 16       

*/
sSNMPset = 
chr(0x30) + chr( 0x31 ) + chr(0x02) + chr( 0x01 ) + chr(0x00) + chr( 0x04 ) + chr(0x06) + chr( 0x70 ) +  chr(0x75) + chr( 0x62 ) + chr(0x6c) + chr( 0x69 ) + chr(0x63) + chr( 0xa3 ) + chr(0x24) + chr( 0x02 ) + 

chr(0x04) + chr( 0x7a ) + chr(0xfc) + chr( 0xc0 ) + chr(0x39) + chr( 0x02 ) + chr(0x01) + chr( 0x00 ) + chr(0x02) + chr( 0x01 ) + chr(0x00) + chr( 0x30 ) + chr(0x16) + chr( 0x30 ) + chr(0x14) + chr( 0x06 ) + 

chr(0x0f) + chr( 0x2b ) + chr(0x06) + chr( 0x01 ) + chr(0x04) + chr( 0x01 ) + chr(0xa2) + chr( 0x79 ) + chr(0x06) + chr( 0x01 ) + chr(0x07) + chr( 0x01 ) + chr(0x01) + chr( 0x01 ) + chr(0x02) + chr( 0x00 ) + 

chr(0x02) + chr( 0x01 ) + chr(nYourNumberHere);      


SetCommunicationHandleValue("udp:10.192.57.39:161", chUDP);

nUDPStatus = OpenOutgoingCommunication( chUDP );


Of course, this is not very pretty, but it sounds like you’ll just be sending perhaps a 0 or one on that last byte (where I had [B]nYourNumberHere[/B]), so perhaps not too horrible.

The next command you’d use after this would be: TransmitString to send out sSNMPSet. You could then do a close. (Or Receive if you’re feeling really adventurous and want to try to parse the reply that comes back…)

-OptoMary

p.s. I used my favorite little free editor, Notepad++ to edit that info from Wireshark, e.g. 30 82… I deleted the left columns and right columns (hold down Alt to highlight columns). I also recorded a Notepad++ macro to add the extra OptoScript syntax like “chr(0x” to save myself some typing.

Write a macro to write your OptoScript, and enjoy more of your weekend! :cool:


#6

Thank you Mary,

That was exactly what I was looking for. I was also able to use the receiveString and substring functions to parse the return data as desired.

John I.