This sample SNMP4J code is using the ported snmp4android.jar
Thank you for all the help thus far....
Not working error states deprecation? --> snmp.sendPDU(pdu, target, null, listener);
Any help would be appreciated, I am sure these are basic Java questions.
Kind Regards,
~ Mike
package snmpman.xxxxxx.com;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.event.ResponseListener;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.smi.VariableBinding;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class DroidActivity extends Activity {
private Snmp snmp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(DroidActivity.this, "Start", Toast.LENGTH_LONG).show();
//Create Target
UdpAddress targetAddress = new UdpAddress("192.168.1.50/161");
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version1);
// creating PDU
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new 开发者_运维百科int[] {1,3,6,1,2,1,1,1})));
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,2})));
pdu.setType(PDU.GETNEXT);
// sending request
ResponseListener listener = new ResponseListener() {
public void onResponse(ResponseEvent event) {
((Snmp)event.getSource()).cancel(event.getRequest(), this);
Toast.makeText(DroidActivity.this, "Received response PDU is: "+event.getResponse(), Toast.LENGTH_LONG).show();
}
};
**snmp.sendPDU(pdu, target, null, listener);**
Toast.makeText(DroidActivity.this, "Done", Toast.LENGTH_LONG).show();
}
}
Try like this :
UdpAddress targetAddress = new UdpAddress("127.0.0.1/1985");
CommunityTarget target = new CommunityTarget();
//...Whatever
target.setAddress(targetAddress);
精彩评论