sendv1trap.java

来自「snmp based application it is used to get」· Java 代码 · 共 64 行

JAVA
64
字号
/*		   Copyright(c) 2003 by Andrew E. Page			  All Rights ReservedPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appears in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the name Andrew E. Page not be usedin advertising or publicity pertaining to distribution of the softwarewithout specific, written prior permission.ANDREW E. PAGE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NOEVENT SHALL ANDREW E. PAGE BE LIABLE FOR ANY SPECIAL, INDIRECT ORCONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OFUSE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OROTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE ORPERFORMANCE OF THIS SOFTWARE.*/package org.netsnmp.examples;import org.netsnmp.DefaultOID;import org.netsnmp.MIBItemNotFound;import org.netsnmp.NetSNMP;import org.netsnmp.NetSNMPSendError;import org.netsnmp.NetSNMPSession;import org.netsnmp.PDU;import org.netsnmp.ASN.INTEGER;/** * Send a Link Up * @author Andrew E. Page <a href=mailto:aepage@users.sourceforge.net>aepage@users.sourceforge.net</a> * */// snmptrap  -v  1  -c  public  manager enterprises.netSnmp test-hub 3 0 '' interfaces.iftable.ifentry.ifindex.1 i 1public class SendV1Trap {  public static void main(String[] args) throws MIBItemNotFound, NetSNMPSendError {  	NetSNMPSession s = new NetSNMPSession() ;  	PDU pdu ;  	  	s.setSNMPVersion(NetSNMP.SNMPv1) ;  	s.setPeerName("localhost:162") ;  	s.setCommunity("public") ;  	s.open() ;  	  	pdu = new PDU(NetSNMP.MSG_TRAP) ; // SNMPv1 Trap  	pdu.enterprise = new DefaultOID("NET-SNMP-MIB::netSnmp") ;  	pdu.trap_type = 3 ;  	pdu.specific_type = 0 ;  	  	pdu.addEntry("IF-MIB::ifEntry.ifIndex.1", new INTEGER(1)) ;  	  	s.send(pdu, null) ; // NOTE there will be no response  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?