0
votes

I am trying to send a SNMP trap specifying the sender's agent ip address. I have been tesing net-snmp snmptrap command and its options but I can't seem to be able to modify the senders address field of the trap itself. I'm looking for something like:

snmptrap -v 2c -c public destination_ip *SOURCE_AGENT_ADDRESS* MIB OID VALUE

If anyone knows if there is any tool out there that can do this or can suggest a python library it would be great.

1

1 Answers

1
votes

If you are using SNMPv1 with the snmptrap tool, it should let you specify agent address explicitly.

If you are using SNMPv2c, there is no dedicated field for agent address in the SNMP packet. But the standard allows you to put your agent address value into a pre-defined variable-binding (1.3.6.1.6.3.18.1.3.0 perhaps). It works in the same way for other legacy SNMPv1 TRAP PDU fields.

You should be able to do that with pysnmp as well:

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    sendNotification(
        SnmpEngine(),
        CommunityData('public'),
        UdpTransportTarget(('demo.snmplabs.com', 162)),
        ContextData(),
        'trap',
        NotificationType(
            ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'),
        ).addVarBinds(
            # agent uptime
            ('1.3.6.1.2.1.1.3.0', 12345),
            # agent address
            ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'),
            # enterprise OID
            ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
            # user variable-bindings may follow
        )
    )
)