Snmpexample.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:1k
- /*
- * @(#)Snmpexample.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import com.adventnet.snmp.snmp2.*;
- public class snmpexample {
- public static void main(String args[]) {
-
- // Start SNMP API
- SnmpAPI api = new SnmpAPI();
- api.setDebug(true);
- // Open session
- SnmpSession session = new SnmpSession(api);
- try
- {
- session.open();
- }
- catch (SnmpException e )
- {
- System.err.println("Error opening socket: "+e);
- }
- // Build Get request PDU
- SnmpPDU pdu = new SnmpPDU();
- UDPProtocolOptions option = new UDPProtocolOptions("localhost");
- pdu.setProtocolOptions(option); //sets the host
- pdu.setCommand(SnmpAPI.GET_REQ_MSG);
- // add OID
- SnmpOID oid = new SnmpOID(".1.3.6.1.2.1.1.1.0");
- pdu.addNull(oid);
- //send request
- try
- {
- SnmpPDU result = session.syncSend(pdu);
- }
- catch (SnmpException e)
- {
- System.err.println("Error sending SNMP request: "+e);
- }
- System.out.println(result.printVarBinds());
- // close session
- session.close();
- //close the api thread
- api.close();
- }
- }