user975068
user975068

Reputation: 73

Setting Peer Address with SNMP4J

I am trying to simulate several virtual SNMP devices using SNMP4J. As such, when sending out traps, I am trying to modify the IP address of the originating device but I am not sure how. I know there is a setPeerAddress() method but it doesn't seem to be working. In fact, I m not even sure if it is even possible or supported by SNMP4J.

Alternately, is it possible to spoof and IP address virtually using Java?

Thanks for all your help in advance.

Upvotes: 1

Views: 986

Answers (2)

kaleemulla sharief
kaleemulla sharief

Reputation: 29

Instead of spoofing, add the IP Address varbind to the trap PDU before forwarding/sending it.

String ip_addr = cmdRespEvent.getPeerAddress().toString().split("/")[0];

pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress,
                    new IpAddress(ip_addr)));

Upvotes: 0

Jolta
Jolta

Reputation: 2725

I am nearly 100% sure that Java will not permit you to spoof the sender address of an IP packet.

Depending on what the operating system permits, it may be possible to do this using calls to JNI methods. I've seen it done for example in the JPcap library when running on Windows.

(Not the popular jpcap hosted at http://jpcap.sourceforge.net/, but the unrelated, identically named, wrapper around winpcap which was previously hosted at http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html . I just noticed that it seems to have disappeared from the web.)

Edit: Regarding the API of SNMP4j, I can only find the setPeerAddress() method in the classes CommandResponderEvent and ResponseEvent. Both of these seem to represent incoming data (responses to requests you sent), so it would not be useful to you to try and change the sender address this way.

Upvotes: 0

Related Questions