Are you trying to send SNMP (v2) traps? The Net::SNMP module does this for you without you needing to worry about the encoding yourself.

I've done some decoding work with Net::SNMPTrapd, but for that I used Convert::ASN1.

I would use Convert::ASN1 also for your task instead of the module you're currently trying with. The following works:

use strict; use warnings; use Convert::ASN1; my $asn = Convert::ASN1->new; $asn->prepare(" varbind SEQUENCE OF SEQUENCE { oid OBJECT IDENTIFIER, choice CHOICE { val_integer INTEGER, val_string STRING, val_OID OBJECT IDENTIFIER, val_IpAddr [APPLICATION 0] STRING, val_Counter32 [APPLICATION 1] INTEGER, val_Guage32 [APPLICATION 2] INTEGER, val_TimeTicks [APPLICATION 3] INTEGER, val_Opaque [APPLICATION 4] STRING, val_Counter64 [APPLICATION 6] INTEGER } } "); my $pdu = $asn->encode( varbind => [ { oid => '1.3.6.1.2.1.1.3.0', choice => { val_TimeTicks => 600 } }, { oid => '1.3.6.1.6.3.1.1.4.1.0', choice => { val_OID => '1.3.6.1.4.1.42767.64.1.1.5.1.40.1' } }, { oid => '1.3.6.1.4.1.42767.64.1.1.3.1.9', choice => { val_integer => 11, } }, { oid => '1.3.6.1.4.1.42767.64.1.1.3.1.10', choice => { val_OID => '1.3.6.1.2.1.26.2.1.1.3.1.9', } }, { oid => '1.3.6.1.4.1.42767.64.1.1.3.1.11', choice => { val_Counter32 => 10, } }, { oid => '1.3.6.1.4.1.42767.64.1.1.3.1.12', choice => { val_TimeTicks => time() } }, { oid => '1.3.6.1.4.1.42767.64.1.1.3.1.13', choice => { val_integer => 2, } }, { oid => '1.3.6.1.4.1.42767.64.1.1.3.1.14', choice => { val_string => '' } } ] ); Convert::ASN1::asn_dump($pdu);

And the output:

VinsWorldcom@C:\Users\VinsWorldcom\tmp> perl test.pl 0000 186: SEQUENCE { 0003 14: SEQUENCE { 0005 8: OBJECT ID = 1.3.6.1.2.1.1.3.0 000F 2: [APPLICATION 3] 0011 : 02 58 __ __ __ __ __ __ __ __ __ __ __ __ __ __ .X 0013 : } 0013 29: SEQUENCE { 0015 10: OBJECT ID = 1.3.6.1.6.3.1.1.4.1.0 0021 15: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.5.1.40.1 0032 : } 0032 19: SEQUENCE { 0034 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.9 0044 1: INTEGER = 11 0047 : } 0047 30: SEQUENCE { 0049 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.10 0059 12: OBJECT ID = 1.3.6.1.2.1.26.2.1.1.3.1.9 0067 : } 0067 19: SEQUENCE { 0069 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.11 0079 1: [APPLICATION 1] 007B : 0A __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ . 007C : } 007C 22: SEQUENCE { 007E 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.12 008E 4: [APPLICATION 3] 0090 : 51 2A C7 73 __ __ __ __ __ __ __ __ __ __ __ __ Q*.s 0094 : } 0094 19: SEQUENCE { 0096 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.13 00A6 1: INTEGER = 2 00A9 : } 00A9 18: SEQUENCE { 00AB 14: OBJECT ID = 1.3.6.1.4.1.42767.64.1.1.3.1.14 00BB 0: STRING = '' 00BD : } 00BD : }

In reply to Re: How to encode snmpv2 trap varbind by VinsWorldcom
in thread How to encode snmpv2 trap varbind by ahm123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.