在SNMP编程中,需要实现tableview,在此总结一下。
操作类SnmpUtil.java:
package com.test.snmp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.Null;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;
public class SnmpUtil {
private static final int DEFAULT_VERSION = SnmpConstants.version1;
private static final String DEFAULT_PROTOCOL = "udp";
private static final int DEFAULT_PORT = 161;
private static final long DEFAULT_TIMEOUT = 3 * 1000L;// milliseconds
private static final int DEFAULT_RETRY = 3;
private static final String DEFAULT_COMMUNITY = "public";//community
public static final String SNMP_VERSION = "SNMP_VERSION";
public static final String SNMP_PROTOCOL = "SNMP_PROTOCOL";
public static final String SNMP_PORT = "SNMP_PORT";
public static final String SNMP_TIMEOUT = "SNMP_TIMEOUT";
public static final String SNMP_RETRY = "SNMP_RETRY";
public static final String SNMP_COMMUNITY= "SNMP_COMMUNITY";
/***
* 创建通信共同体,指定IP
* @param ip
* @param port
* @