如果您使用带有snmptrap 工具的SNMPv1,它应该允许您明确指定代理地址。
如果您使用的是 SNMPv2c,则 SNMP 数据包中没有代理地址的专用字段。但是该标准允许您将代理地址值放入预定义的变量绑定中(可能是1.3.6.1.6.3.18.1.3.0)。它对其他传统 SNMPv1 TRAP PDU 字段的工作方式相同。
pysnmp 也应该可以做到这一点:
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
)
)
)