// Home | Go Back //
import com.ireasoning.protocol.*;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.util.ParseArguments;
public class snmpset extends snmp
{
SnmpVarBindList _vblist = new SnmpVarBindList();
public static void main(String[] args)
{
snmpset s = new snmpset();
s.parseOptions(args, "snmpset");
s.snmpSet();
}
private void snmpSet()
{
try
{
SnmpSession session = new SnmpSession(_host, _port, _community,
_community, _version);
if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword, _privProtocol, _privPassword, _context, null);
}
SnmpPdu pdu = new SnmpPdu(SnmpConst.SET);
pdu.addVarBinds(_vblist);
SnmpPdu retPdu = session.snmpSetRequest(pdu);
print(retPdu);
session.close();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
protected void parseArgs()
{
String [] as = _parseArgs.getArguments();
if(as.length > 0)
{
_host = as[0];
}
int start = 1;
while(start < as.length)
{
String oid = as[start];
SnmpOID o = MibUtil.lookupOID(oid);
String type = as[start + 1];
String value = as[start + 2];
SnmpDataType t = translate(type, value);
SnmpVarBind vb = new SnmpVarBind(o, t);
_vblist.add(vb);
start += 3;
}
}
protected void usage(String programName, boolean allowMultipleOIDs)
{
System.out.println( "Usage: java " + programName +
" [options...] <hostname> [<OID> <type> <value> ...]\n");
System.out.println( "<OID>\tobject identifier");
System.out.println( "<type>\tdata type of the value, one of i, u, t, a, o, s, c, g." +
" i: INTEGER, u: unsigned INTEGER, t: TIMETICKS, " +
"a: IPADDRESS, o: OID, s: STRING, c: counter, g: gauge, , x: hex data (in \"0x1B 0xAC ...\" format)");
System.out.println( "<value>\tvalue of this object identifier");
}
protected void printExample(String programName)
{
System.out.println( "java " + programName + " localhost .1.3.6.1.2.1.1.4.0 s test");
System.out.println( "java " + programName + " -c setcommunity localhost .1.3.6.1.2.1.1.4.0 s test");
System.out.println( "java " + programName + " localhost .1.3.6.1.2.1.1.4.0 s test " +
".1.3.2.12.1.3.0 i 345");
}
}