| |

VerySource

 Forgot password?
 Register
Search
View: 837|Reply: 3

Ask you a snmp4j related question

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-22 09:40:01
| Show all posts |Read mode
I want to use snmp4j to communicate with the device. Is it necessary to know the version of snmp, and how to get oid and oid?
           String ip = "192.168.100.1";
           Address targetAddress = GenericAddress.parse ("udp:" + ip + "/ 161");
            log.debug ("ip" + ip);
            TransportMapping transport;
            transport = new DefaultUdpTransportMapping ();
            Snmp snmp = new Snmp (transport);
            transport.listen ();
            CommunityTarget target = new CommunityTarget ();
            target.setCommunity (new OctetString ("public"));
            target.setAddress (targetAddress);
            target.setRetries (2);
            target.setTimeout (1000);
            target.setVersion (SnmpConstants.version1);
            // creating PDU
            PDU pdu = new PDU ();

            String oidPrefix = "1.3.6.1.2.1.1.1";
            pdu.add (new VariableBinding (new OID (oidPrefix)));
            pdu.setType (PDU.GET);

            ResponseEvent event = snmp.send (pdu, target);
            PDU resposePDU = event.getResponse ();
     
            Vector result = resposePDU.getVariableBindings ();
            VariableBinding vb = (VariableBinding) result.get (0);
            String sID = vb.getVariable (). ToString ();
            log.debug ("sID" + sID);

This is not correct.Why is the value in result every time empty? I have given an example. Thank you.
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-4-22 23:45:01
| Show all posts
Ha ha, never seen, help top
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-23 23:00:02
| Show all posts
First, make sure that the device is open for permission for you to access, and then you need to retrieve the ID and OID according to the MIB file to compile and view the index of the corresponding index, and then test to obtain the value you want
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-15 23:15:01
| Show all posts
Change 1.3.6.1.2.1.1.1 to 1.3.6.1.2.1.1.1.0 and have a try
study together
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list