[SNMP4J] Need help:Unable to run sample snmp code with OIDs

2011-02-16 Thread anshul gupta
Hi, We are working on college project. We are unable to solve the
 problem that we have come up while coding. Please, help us.Here is our code.
//import java.net.InetAddress;import
 org.snmp4j.CommunityTarget;import org.snmp4j.PDU;import
 org.snmp4j.Snmp;import org.snmp4j.TransportMapping;import 
org.snmp4j.event.ResponseEvent;import org.snmp4j.event.ResponseListener;import 
org.snmp4j.mp.SnmpConstants;import org.snmp4j.smi.*;import 
org.snmp4j.transport.DefaultUdpTransportMapping;//import 
java.lang.NullPointerException;public class SNMP4JHelper{ public static final 
int SNMP_PORT = 161;public static final String READ_COMMUNITY = 
public;   public static final String WRITE_COMMUNITY= private;  public 
static final int mSNMPVersion =0; // 0 represents
 SNMP version=1 public static final String OID_Hard_disk = 
1.3.6.1.2.1.1.3.0;//1.3.6.1.4.1.2021.9.1.7.1;//  
.1.3.6.1.4.1.2021.4.4.0;//

1.3.6.1.4.1.311.1.1.3.1.1.5.1.3;  
//1.3.6.1.4.1.318.1.1.1.12.3.2.1.3.1; //public static final String 
OID_UPS_BATTERY_CAPACITY=1.3.6.1.4.1.318.1.1.1.2.2.1.0;  public static void 
main(String[] args)  {   try {// 
172.20.1.150  String strIPAddress = 127.0.0.1;  
SNMP4JHelper objSNMP = new SNMP4JHelper();  
//objSNMP.snmpSet();int Value = 1;  
/// //Set Value=2 
to trun OFF UPS OUTLET
 Group1 //Value=1 to trun ON UPS OUTLET Group1  
//  
//  strIPAddress, WRITE_COMMUNITY,OID_Hard_disk, Value//  
UPS_OUTLET_GROUP1   objSNMP.snmpSet(strIPAddress, 
WRITE_COMMUNITY,OID_Hard_disk,
 Value);

//  
//Get Basic state of UPS
/   
String batteryCap 
=objSNMP.snmpGet(strIPAddress,READ_COMMUNITY,OID_Hard_disk);  

}   catch (Exception e) {   
e.printStackTrace();}
}   /*   * The following code valid only SNMP version1. This
 * method is very useful to set a parameter on remote device.* */       
public void snmpSet(String strAddress, String community, String strOID, int 
Value)  {   strAddress= strAddress+/+SNMP_PORT;   
Address
 targetAddress = GenericAddress.parse(strAddress);  Snmp snmp;  
try {   TransportMapping transport
 = new DefaultUdpTransportMapping();snmp = new 
Snmp(transport); transport.listen(); 
CommunityTarget target = new CommunityTarget(); 
target.setCommunity(new OctetString(community));
target.setAddress(targetAddress);   target.setRetries(2);   
target.setTimeout(5000);
target.setVersion(SnmpConstants.version1);  PDU pdu = new 
PDU();//  pdu.add(new VariableBinding(new OID(strOID), new 
Integer32(Value)));pdu.setType(PDU.SET);   
ResponseListener listener = new ResponseListener()  {   
public void onResponse(ResponseEvent event) 

{   // Always cancel async request 
when response has been received  // otherwise a 
memory leak is created! Not canceling a request  

// immediately can be
 useful when sending a request to a broadcast   
// address  
((Snmp)event.getSource()).cancel(event.getRequest(), this); 
if ( event.getResponse() != null )  
{   System.out.println(Set 
Status is:+event.getResponse().getErrorStatusText());  
}   }   };  

snmp.send(pdu, target, null, listener); 
snmp.close();   
}   catch (Exception e) {   
e.printStackTrace();}   }   /*   * The 
code is valid only SNMP version1.
 SnmpGet method  * return Response for given OID from the Device.*/ 
    public
 String snmpGet(String strAddress, String community, String strOID) {   
String str=;  try {   

  

[SNMP4J] (no subject)

2011-02-16 Thread anshul gupta



___
SNMP4J mailing list
SNMP4J@agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j


[SNMP4J] Need help:Unable to run sample snmp code with OIDs

2011-02-16 Thread anshul gupta
Hi,
I have send u a code in my last mail and before that 
u asked some questions mentioned below


Is the community correct?
Target address correct?
Is the agent running?


Actually we are new to the project so we are not 
able to understand the question asked by u so if possible
from the code provided by me please if u can help us to answer
your question please


Regards
Anshul


___
SNMP4J mailing list
SNMP4J@agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j


Re: [SNMP4J] Need help:Unable to run sample snmp code with OIDs

2011-02-16 Thread Frank Fock
Hi,

I am not able to help if you cannot
answer the questions. May be a good
book about IP networking and SNMP
could help you out.

Best regards,
Frank

On 16.02.2011 15:56, anshul gupta wrote:
 Hi,
 I have send u a code in my last mail and before that
 u asked some questions mentioned below


 Is the community correct?
 Target address correct?
 Is the agent running?


 Actually we are new to the project so we are not
 able to understand the question asked by u so if possible
 from the code provided by me please if u can help us to answer
 your question please


 Regards
 Anshul


 ___
 SNMP4J mailing list
 SNMP4J@agentpp.org
 http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com

___
SNMP4J mailing list
SNMP4J@agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j


Re: [SNMP4J] Discover SNMPv3 Devices

2011-02-16 Thread Frank Fock
Hi Daniel,

What your are going to try is simply impossible.
You cannot use multicast with SNMPv3, because
each agent has its unique engine ID and the manager
must use that ID it its requests.

Best regards,
Frank

On 15.02.2011 09:27, Daniel Boschofsky wrote:
 Hi there,

 I am pretty new to mailinglists and SNMP4J.

 I am trying to write a little application which lists all SNMPv3 devices in
 the network and show some information. Reading information from a single
 known host is no problem at all, but I cant discover all devices. I tried it
 via a simple broadcast but it ends with a NullPointerException. If I use the
 snmpgetnext command from bash, I get an Unknown Engine ID (Permission
 denied). Probably it is the same problem with SNMP4J. So how can I send a
 simple SNMPv3 request to all nodes without incrementing the IP and sending
 the request to each existing address in the network.

 Sincerely,
 Daniel B.

 ---
 My code so far for testing:

 public static void main(String[] args) {
 Snmp snmp;
 Address targetAddress = GenericAddress.parse(udp:10.13.255.255/161);
 TransportMapping transport = new DefaultUdpTransportMapping();
 snmp = new Snmp(transport);
 USM usm = new USM(SecurityProtocols.getInstance(),
 new OctetString(MPv3.createLocalEngineID()),
 0);

 SecurityModels.getInstance().addSecurityModel(usm);
 transport.listen();

 snmp.getUSM().addUser(new OctetString(HelloSnmp),
 new UsmUser(new OctetString(HelloSnmp),
 AuthMD5.ID,
 new OctetString(Hello123),
 PrivDES.ID,
 new OctetString(Hello123)));

 UserTarget target = new UserTarget();
 target.setAddress(targetAddress);
 target.setRetries(1);
 target.setTimeout(5000);
 target.setVersion(SnmpConstants.version3);
 target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
 target.setSecurityName(new OctetString(HelloSnmp));

 OID targetOID = new OID(.1.3.6.1.2.1.1.5);
 PDU pdu = new ScopedPDU();
 pdu.add(new VariableBinding(targetOID));
 pdu.setType(PDU.GETNEXT);

 ResponseEvent response = snmp.send(pdu,target);
 PDU responsePDU = response.getResponse();
 System.out.println(responsePDU.get(0));
 snmp.close();
 }
 ___
 SNMP4J mailing list
 SNMP4J@agentpp.org
 http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com

___
SNMP4J mailing list
SNMP4J@agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j