使用 SNMP4J 从 PDU 数据包中检索目标 IP 地址

问题描述 投票:0回答:1

我在从收到的 pdu 中检索目标 IP 地址时遇到问题。 “getPeerAddress()”给了我发件人的 IP 地址。但我想要的是命令/收到的 pdu 中的 ip 地址或主机名。

例如“10.255.255.221”来自

snmpset -v 1 -c M 10.255.**.221 1.3.6.1.4.1.161.3.6.37.2.6.1.1.4.2 i 3。

我尝试了 pduV1 的 getAgentAdress 但没有显示任何内容。

public synchronized void processPdu(CommandResponderEvent cmdRespEvent) {
System.out.println("Received PDU...");

String retrieveIP = cmdRespEvent.getPeerAddress().toString().split("/")[0];
System.out.println("Received PDU from " + retrieveIP  +"\n");

PDU pdu = cmdRespEvent.getPDU();
System.out.println(" PDU Type = " + PDU.getTypeString(pdu.getType()));
System.out.println("Trap Type = " + pdu.getType());
System.out.println("IP Address = " + ((PDUv1) pdu).getAgentAddress().toString());
String updateValue = pdu.get(0).getVariable().toString();
System.out.println("updateValue ="+updateValue);
}

编辑:我的机器有多个IP地址

java net-snmp snmp4j pdu
1个回答
0
投票

问题解决了吗?我最近也遇到了同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.