Tech Off Thread

8 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

.NET and SNMP Client

Back to Forum: Tech Off
  • User profile image
    Travis H

    I've already written a UDPClient, and am going to send SNMP packets to a device.

    I need to know how to encode the packets, with the SNMP header... so that they are valid, and interperted as SNMP commands.

    Any help is appreciated.

  • User profile image
    Travis H

    I use Eithereal to capture packets from another application, and it returns...

    0000  00 11 88 1c 85 19 00 07  e9 43 dd a2 08 00 45 00   ........ .C....E.
    0010  00 45 07 fc 00 00 81 11  1b a6 0a 00 01 03 0a 01   .E...... ........
    0020  01 03 12 ea 00 a1 00 31  d7 3d 30 27 02 01 00 04   .......1 .=0'....
    0030  06 70 75 62 6c 69 63 a0  1a 02 02 0e 2c 02 01 00   .public. ....,...
    0040  02 01 00 30 0e 30 0c 06  08 2b 06 01 02 01 0b 09   ...0.0.. .+......
    0050  00 05 00                                           ...             


    my application returns...

    0000  00 11 88 1c 85 19 00 07  e9 43 dd a2 08 00 45 00   ........ .C....E.
    0010  00 30 0c dd 00 00 81 11  16 da 0a 00 01 03 0a 01   .0...... ........
    0020  01 03 09 4c 00 a1 00 1c  26 04 67 65 74 20 73 79   ...L.... &.get sy
    0030  73 74 65 6d 2e 73 79 73  4e 61 6d 65 2e 30         stem.sys Name.0 



    so it's pretty obvious that im missing some crucial information... like, the packet header Wink

    "Couldn't Parse Message Header: Wrong type for that item."

    The commands i'm sending are "get system.sysname.0"

    Okay.  Well, I guess I need to someone read that and make a packet header on my app?

    Im using sockets, and am just using the ASCIIEncoding.GetBytes("SNMP Command") to send it... so it goes something like this:

    UDPClient.Sent(ASCIIEncoding.GetBytes("MyCommand"))

    however, I need to include the SNMP header in the packet so that I will recongnize it, right?

    Basically.. what I want to do is use VB.NET to make a client that can send "SET" commands to a SNMP client.

  • User profile image
    out180

    Wow there's a lot of RFC's on SNMP.  Perplexed

    Try digging through the docs over on the Net-SNMP project at sourceforge.  http://net-snmp.sourceforge.net/

    If nothing else you can always ask the lead dev there for input or dig through their source.  It's in C but contains a decent amount of comments.  It should be a good place to start.

  • User profile image
    Travis H

    Okay, Thanks.

    I really don't know how to make the SNMP header... do I I just declare a variable as a string, and add the text to it as the header?

    Something like...

    Dim HeaderStr as String = "\nsnmpset v1 public \n public 161 20 0"

    and as far as that string, I have no idea whether that is the actual header or now.  I know that the header has the version and community, but I dont know how it's seperated or anything.

    Nor do I know how to actually tell it what to do, I know the command I want to issue is something like "SET 1.3.6.1.2.1.2.2.1.7.3 3"... that shound SET 1.3.6.1.2.1.2.2.1.7.3 = 3, right?

    And if so.. how do I go about building the packet correctly?

  • User profile image
    Travis H

    Anyone have any news on how to correctly build an SNMP packet header.. and overall packet?

  • User profile image
    Tyler Brown

    Haven't done anything of the sort in C#, but a quick Google search revealed the following resources you may find of use.

    Raw Ethernet Packet Sending
    C# Network Programming: Chapter 7

    It seems that the PDF file of C# Network Programming is a sample chapter available from Sybex. Might contain some useful stuff, perhaps enough to warrant you going out to purchase the book if you find it of use.

  • User profile image
    out180

    This has promise.  It's simple sure but down in the meat of the SNMP class you can see how the packet is built.  In C#

    http://www.java2s.com/Code/CSharp/Network/SimpleSNMP.htm

    The code might be from the Sybex book mentioned above.

  • User profile image
    thatsparesh

    Hi,
    The code posted on link works really fine.. and its great to see it hasnt used any api's or dll's
    Do u have any info about how to encode/decode other snmp commands too.  (snmpwalk, snmptranslate, snmptable and specially snmpset)
    Any help would be greatly appreciated..
    Thank you..

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.