3 Replies Latest reply: Jan 6, 2005 10:37 AM by DrClap RSS

    how to??

    807596
      Hi, some body who knows snmp can help me. Below is my program and would like to know how to extract the value i needed,
      import java.util.Vector;
      import java.net.*;
      import java.lang.*;
      import java.util.*;
      import com.adventnet.snmp.snmp2.*;
      //import java.io.Serializable;
      import com.adventnet.snmp.beans.*;
      
      public class BroadcastAddress {
      
      
      public BroadcastAddress() {
      }
      
      void startDiscovery ()
      {
      String _remAddress = new String();
      Vector _agentAddresses = new Vector(255); 
      String _agentAddString = new String();
      
      
      System.out.println("About to discover agents");
      String OID = ".1.3.6.1.2.1.1.3.0"; 
      SnmpAPI api;
      api = new SnmpAPI();
      api.start();
      api.setDebug( true );
      
      String agentAddress = "172.26.1.255";
      SnmpSession session = new SnmpSession(api);
      try {
      session.open();
      }
      catch (SnmpException e ) {
      System.err.println("Error opening socket: "+e);
      }
      SnmpPDU pdu = new SnmpPDU();
      pdu.setCommand(api.GET_REQ_MSG );
      SnmpOID oid = new SnmpOID(OID);
      pdu.addNull(oid);
      session.setPeername(agentAddress);
      
      try{
           
      //pdu = session.syncSend(pdu);
      /*pdu =*/ session.send(pdu);
      
      
      
      System.out.println("Address of remote agent :" +pdu.getRemoteHost());
      _agentAddresses.add( pdu.getRemoteHost());
      }
      catch (SnmpException e) {
      System.err.println("Error sending SNMP request:"+e);
      }
      catch (Exception e ) {
      System.err.println("Not an agent in : " + agentAddress);
      }
      session.close();
      _agentAddString = _agentAddresses.toString();
      System.out.println("Agents on these addresses:" +_agentAddString);
      api.close();
      }
      
      
      public static void main(String args[])
      {
      BroadcastAddress objBroad = new BroadcastAddress();
      objBroad.startDiscovery();
      }
      
      
      }
      output of the program is
      About to discover agents

      AdventNet SNMP API 4 SP3 ( Release 4.0.3 )
      Sent Type: GET. RequestID: 1 to "172.26.1.255:161".
      Sent Time: Thu Jan 06 14:42:14:798 GMT+05:30 2005
      Length of SNMP DATA: 40
      DATA
      30 26 02 01 00 04 06 70 75 62 6c 69 63 a0 19 02 01 01 02 01
      00 02 01 00 30 0e 30 0c 06 08 2b 06 01 02 01 01 03 00 05 00

      Packet from: 172.26.1.176:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:798 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      03 2f 5c 5c


      Packet from: 172.26.1.72:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:798 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      04 a8 12


      Packet from: 172.26.1.219:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:798 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      01 a1 af 35


      Packet from: 172.26.1.32:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:798 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      01 06 83 09


      Packet from: 172.26.1.174:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:798 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      01 10 78 f7


      Packet from: 172.26.1.236:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:813 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      01 ab 29 28


      Packet from: 172.26.1.69:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:813 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      7d d3 48


      Packet from: 172.26.1.238:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:813 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      10 cc 7c


      Packet from: 172.26.1.177:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:813 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      0e 8f 2c


      Packet from: 172.26.1.51:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:813 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      0a ca 3a


      Packet from: 172.26.1.205:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:813 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      01 14 19 7e


      Packet from: 172.26.1.221:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:813 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      0c 15 2d


      Packet from: 172.26.1.38:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:923 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      0a 2c 7e


      Packet from: 172.26.1.169:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:923 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      03 89 cc 91


      Packet from: 172.26.1.47:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:938 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      01 7c cb 27


      Packet from: 172.26.1.213:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:14:938 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      11 8d eb


      Packet from: 172.26.1.209:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:048 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      03 9e 43


      Packet from: 172.26.1.71:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:048 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      01 a0 1e 41


      Packet from: 172.26.1.231:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:048 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      10 a3 7d


      Packet from: 172.26.1.37:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:048 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      13 46 e2


      Packet from: 172.26.1.237:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:173 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      17 62 31


      Packet from: 172.26.1.211:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:173 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      7a 85 c2


      Packet from: 172.26.1.242:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:173 GMT+05:30 2005
      Length of SNMP DATA: 44
      DATA:
      30 2a 02 01 00 04 06 70 75 62 6c 69 63 a2 1d 02 01 01 02 01
      00 02 01 00 30 12 30 10 06 08 2b 06 01 02 01 01 03 00 43 04
      03 28 4b c0


      Packet from: 172.26.1.45:161 RequestID: 1
      Received Time: Thu Jan 06 14:42:15:266 GMT+05:30 2005
      Length of SNMP DATA: 43
      DATA:
      30 29 02 01 00 04 06 70 75 62 6c 69 63 a2 1c 02 01 01 02 01
      00 02 01 00 30 11 30 0f 06 08 2b 06 01 02 01 01 03 00 43 03
      08 5d f3

      Address of remote agent :172.26.1.255
      Agents on these addresses:[172.26.1.255]

      My query here is i need only IP of the alive system, not the complete pdu data. How can i achieve that. any pointers please. Thanks for the help.
        • 1. Re: how to??
          807596
          You'll need to learn something about ASN.1. Search for the tool "dumpasn1" (it's a C program and it's available from the Peter Gutmann's site) and go to the site http://www.oss.com and download the free books about ASN.1. For instance, converting some of your output sequences to binary and submitting them to the DUMPASN1 tool, you can get the following outputs:
          dumpasn1 test.bin
             0 30   41: SEQUENCE {
             2 02    1:   INTEGER 0
             5 04    6:   OCTET STRING 'public'
            13 A2   28:   [2] {
            15 02    1:     INTEGER 1
            18 02    1:     INTEGER 0
            21 02    1:     INTEGER 0
            24 30   17:     SEQUENCE {
            26 30   15:       SEQUENCE {
            28 06    8:         OBJECT IDENTIFIER '1 3 6 1 2 1 1 3 0'
            38 43    3:         [APPLICATION 3]
                      :           04 A8 12
                      :         }
                      :       }
                      :     }
                      :   }

          0 warnings, 0 errors.
          dumpasn1 test.bin
             0 30   41: SEQUENCE {
             2 02    1:   INTEGER 0
             5 04    6:   OCTET STRING 'public'
            13 A2   28:   [2] {
            15 02    1:     INTEGER 1
            18 02    1:     INTEGER 0
            21 02    1:     INTEGER 0
            24 30   17:     SEQUENCE {
            26 30   15:       SEQUENCE {
            28 06    8:         OBJECT IDENTIFIER '1 3 6 1 2 1 1 3 0'
            38 43    3:         [APPLICATION 3]
                      :           04 A8 12
                      :         }
                      :       }
                      :     }
                      :   }

          0 warnings, 0 errors.
          dumpasn1 test.bin
             0 30   42: SEQUENCE {
             2 02    1:   INTEGER 0
             5 04    6:   OCTET STRING 'public'
            13 A2   29:   [2] {
            15 02    1:     INTEGER 1
            18 02    1:     INTEGER 0
            21 02    1:     INTEGER 0
            24 30   18:     SEQUENCE {
            26 30   16:       SEQUENCE {
            28 06    8:         OBJECT IDENTIFIER '1 3 6 1 2 1 1 3 0'
            38 43    4:         [APPLICATION 3]
                      :           01 A1 AF 35
                      :         }
                      :       }
                      :     }
                      :   }

          0 warnings, 0 errors.
          dumpasn1 test.bin
             0 30   42: SEQUENCE {
             2 02    1:   INTEGER 0
             5 04    6:   OCTET STRING 'public'
            13 A2   29:   [2] {
            15 02    1:     INTEGER 1
            18 02    1:     INTEGER 0
            21 02    1:     INTEGER 0
            24 30   18:     SEQUENCE {
            26 30   16:       SEQUENCE {
            28 06    8:         OBJECT IDENTIFIER '1 3 6 1 2 1 1 3 0'
            38 43    4:         [APPLICATION 3]
                      :           01 06 83 09
                      :         }
                      :       }
                      :     }
                      :   }

          0 warnings, 0 errors.
          dumpasn1 test.bin
             0 30   42: SEQUENCE {
             2 02    1:   INTEGER 0
             5 04    6:   OCTET STRING 'public'
            13 A2   29:   [2] {
            15 02    1:     INTEGER 1
            18 02    1:     INTEGER 0
            21 02    1:     INTEGER 0
            24 30   18:     SEQUENCE {
            26 30   16:       SEQUENCE {
            28 06    8:         OBJECT IDENTIFIER '1 3 6 1 2 1 1 3 0'
            38 43    4:         [APPLICATION 3]
                      :           01 06 83 09
                      :         }
                      :       }
                      :     }
                      :   }

          0 warnings, 0 errors.
          • 2. Re: how to??
            807596
            Hi, Thanks for the response. Since i am newbie and eager to know and learn the things, hoping better expalination from your side. Please help me.
            • 3. Re: how to??
              DrClap
              That was fast. In under an hour you downloaded all that information and read it?