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
)
)
)