// Home | Go Back //
import com.ireasoning.protocol.TimeoutException;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.util.ParseArguments;
import java.io.IOException;
public class snmpgetnext extends snmp
{
static int _getNextMethod = 1;
public static void main(String[] args)
{
snmpgetnext s = new snmpgetnext();
s.parseOptions(args, "snmpgetnext");
if(_getNextMethod == 1)
{ s.getnext1();
}
else if(_getNextMethod == 2)
{ s.getnext2();
}
}
private void getnext1()
{
try
{
SnmpSession session = new SnmpSession(_host, _port, _community,
_community, _version, _transportLayer);
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword,
_privProtocol, _privPassword, _context, null);
}
SnmpPdu retPdu = session.snmpGetNextRequest(_oids);
print(retPdu);
session.close();
}
catch(TimeoutException timeout)
{
System.out.println( "time out");
}
catch(IOException e)
{
System.out.println(e);
e.printStackTrace();
}
}
private void getnext2()
{
try
{
SnmpTarget target = new SnmpTarget(_host, _port,
_community, _community, _version);
SnmpSession session = new SnmpSession(target, _transportLayer);
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword,
_privProtocol, _privPassword, _context, null);
}
SnmpVarBind[] vblist = new SnmpVarBind[_oids.length];
for (int i = 0; i < vblist.length ; i++)
{
vblist[i] = new SnmpVarBind(_oids[i]);
}
SnmpPdu pdu = new SnmpPdu(SnmpConst.GET_NEXT, vblist);
SnmpPdu retPdu = session.send(pdu);
print(retPdu);
session.close();
}
catch(TimeoutException timeout)
{
System.out.println( "time out");
}
catch(IOException e)
{
System.out.println(e);
e.printStackTrace();
}
}
protected void moreOptions()
{
System.out.println( "-w {1|2} which getnext method to use, default is 1");
}
protected void parseOptions(String[] args, String program)
{
super.parseOptions(args, program);
_getNextMethod = Integer.parseInt(_parseArgs.getOptionValue('w', "1"));
}
protected void printMoreOptions()
{
System.out.println( "getnext-method =\t" + _getNextMethod);
}
protected void printExample(String programName)
{
System.out.println( "java " + programName + " localhost .1.3.6.1.2.1.1.3.0");
System.out.println( "java " + programName + " localhost sysUpTime");
System.out.println( "java " + programName +
" localhost -v 3 -u newUser -A abc12345 -X abc12345 .1.3" );
}
protected ParseArguments newParseArgumentsInstance(String[] args)
{
return new ParseArguments(args, "?ho", "utvaAXxcpmnrwk");
}
}