Exemplo n.º 1
0
#construct compiled template packets used in main module

import usnmp
import binascii

# SEQ
#   INT version = SNMP_VER1
#   STR community = "public"
#   TYPE [get|set] = SNMP_GETREQUEST
#       INT request_id = 0
#       INT error status = 0
#       INT error index = 0
#       SEQ
#           of variable binding = empty
gs = usnmp.tobytes_tv(usnmp.ASN1_SEQ, b'')
gs = usnmp.tobytes_tv(usnmp.ASN1_INT, 0) + \
        usnmp.tobytes_tv(usnmp.ASN1_INT, 0) + \
        usnmp.tobytes_tv(usnmp.ASN1_INT, 0) + gs
gs = usnmp.tobytes_tv(usnmp.SNMP_GETREQUEST, gs)
gs = usnmp.tobytes_tv(usnmp.ASN1_INT, usnmp.SNMP_VER1) + \
        usnmp.tobytes_tv(usnmp.ASN1_OCTSTR, "public") + gs
gs = usnmp.tobytes_tv(usnmp.ASN1_SEQ, gs)
gs
binascii.hexlify(gs)

# SEQ
#   INT version = SNMP_VER1
#   STR community = "public"
#   TYPE [trap] = SNMP_TRAP
#       OID enterprise oid = "1.3.6.1.4.1" (root of enterprise oid's)
#       IP ip address = 127.0.0.1
Exemplo n.º 2
0
#getresponse
s="3081d20201000403414643a281c702043821eea10201000201003081b8300f060a2b0601020102020101010201013013060a2b0601020102020102010405566c616e31300f060a2b0601020102020103010201353010060a2b060102010202010401020205dc3012060a2b06010201020201050142043b9aca003014060a2b0601020102020106010406001b8ff4d1c0300f060a2b060102010202010701020102300f060a2b0601020102020108010201023010060a2b06010201020201090143022c06300f060a2b060102010202010a01410100"

b=bytes(ubinascii.unhexlify(s))

usnmp.frombytes_tvat(b,0)
usnmp.frombytes_tvat(b,3)
usnmp.frombytes_tvat(b,6)
usnmp.frombytes_tvat(b,11)
usnmp.frombytes_tvat(b,14)
usnmp.frombytes_tvat(b,20)
usnmp.frombytes_tvat(b,23)
usnmp.frombytes_tvat(b,26)

usnmp.tobytes_tv(4, "hello world")
usnmp.frombytes_tvat(usnmp.tobytes_tv(4, b"hello world"),0)

usnmp.frombytes_tvat(usnmp.tobytes_tv(usnmp.ASN1_INT,12311),0)[1] == 12311
usnmp.frombytes_tvat(usnmp.tobytes_tv(usnmp.SNMP_GUAGE,23),0)[1] == 23
usnmp.frombytes_tvat(usnmp.tobytes_tv(usnmp.SNMP_TIMETICKS,65783634),0)[1] == 65783634
usnmp.frombytes_tvat(usnmp.tobytes_tv(usnmp.ASN1_NULL,None),0)[1] == None
usnmp.frombytes_tvat(usnmp.tobytes_tv(usnmp.ASN1_OID,"1.3.1.2.2.4324.2"),0)[1] == "1.3.1.2.2.4324.2"
usnmp.frombytes_tvat(usnmp.tobytes_tv(usnmp.SNMP_IPADDR,"172.26.235.23"),0)[1] == "172.26.235.23"

p = usnmp.SnmpPacket(b)
p.ver
p.community
p.type
p.id
p.err_status
Exemplo n.º 3
0
# construct compiled template packets used in main module

import usnmp
import binascii

# SEQ
#   INT version = SNMP_VER1
#   STR community = "public"
#   TYPE [get|set] = SNMP_GETREQUEST
#       INT request_id = 0
#       INT error status = 0
#       INT error index = 0
#       SEQ
#           of variable binding = empty
gs = usnmp.tobytes_tv(usnmp.ASN1_SEQ, b"")
gs = (
    usnmp.tobytes_tv(usnmp.ASN1_INT, 0) + usnmp.tobytes_tv(usnmp.ASN1_INT, 0) + usnmp.tobytes_tv(usnmp.ASN1_INT, 0) + gs
)
gs = usnmp.tobytes_tv(usnmp.SNMP_GETREQUEST, gs)
gs = usnmp.tobytes_tv(usnmp.ASN1_INT, usnmp.SNMP_VER1) + usnmp.tobytes_tv(usnmp.ASN1_OCTSTR, "public") + gs
gs = usnmp.tobytes_tv(usnmp.ASN1_SEQ, gs)
gs
binascii.hexlify(gs)

# SEQ
#   INT version = SNMP_VER1
#   STR community = "public"
#   TYPE [trap] = SNMP_TRAP
#       OID enterprise oid = "1.3.6.1.4.1" (root of enterprise oid's)
#       IP ip address = 127.0.0.1
#       INT trap generic type = 0