[SNMP4J] about the private mib

宋学孟 playgod1984 at hotmail.com
Thu Jul 9 02:08:04 CEST 2009


hi all,hi Frank,
    public void initComm() throws IOException {
  targetAddress = GenericAddress.parse("udp:10.66.244.132/161");
  // 设置接收trap的IP和端口
  transport = new DefaultUdpTransportMapping(new UdpAddress());
  CommunityTarget target = new CommunityTarget();
  target.setCommunity(new OctetString("public"));
  target.setAddress(targetAddress);
  // 通信不成功时的重试次数
  target.setRetries(2);
  // 超时时间
  target.setTimeout(1500);
  target.setVersion(SnmpConstants.version2c);
  snmp = new Snmp(transport);
  transport.listen();
 }
 public ResponseEvent sendPDU(PDU pdu) throws IOException {
  // 设置 target

  // 设置 target
  CommunityTarget target = new CommunityTarget();
  target.setCommunity(new OctetString("public"));
  target.setAddress(targetAddress);
  // 通信不成功时的重试次数
  target.setRetries(2);
  // 超时时间
  target.setTimeout(1500);
  target.setVersion(SnmpConstants.version1);
  // 向Agent发送PDU,并返回Response
  return snmp.send(pdu, target);
 }

 public void setPDU() throws IOException {
  // set PDU
  OID oid = new OID(".1.3.6.1.2.1.17.7.1.4.3.1.1");
  PDU pdu = new PDU();
  pdu.add(new VariableBinding(oid, new OctetString(command)));
  System.out.println("显示设置命令" + command);
  pdu.setType(PDU.SET);
  sendPDU(pdu);
 }
public static void main(String[] args) {
  try {
   SnmpUtil util = new SnmpUtil("", "", "");
   util.initComm();
    util.setPDU();
//   util.getPDU("");
  } catch (IOException e) {
   e.printStackTrace();
  }
 }


i use methord setPDU() could set the info for stand mib but could not set for private mib,could you help me .thanks a lot



More information about the SNMP4J mailing list