This blog is a knowledge base...where I clip cool tricks and urls

Simple SNMP

From Richard Blum
clipped from www.java2s.com
// Send sysName SNMP request
      response = conn.get("get", argv[0], argv[1]"1.3.6.1.2.1.1.5.0");
      if (response[0== 0xff)
      {
         Console.WriteLine("No response from {0}", argv[0]);
         return;
      }

      // If response, get the community name and MIB lengths
      commlength = Convert.ToInt16(response[6]);
      miblength = Convert.ToInt16(response[23 + commlength]);

      // Extract the MIB data from the SNMP response
      datatype = Convert.ToInt16(response[24 + commlength + miblength]);
      datalength = Convert.ToInt16(response[25 + commlength + miblength]);
      datastart = 26 + commlength + miblength;
      output = Encoding.ASCII.GetString(response, datastart, datalength);
      Console.WriteLine("  sysName - Datatype: {0}, Value: {1}",
              datatype, output);

      // Send a sysLocation SNMP request
      response = conn.get("get", argv[0], argv[1]"1.3.6.1.2.1.1.6.0");
      if (response[0== 0xff)
      {
         Console.WriteLine("No response from {0}", argv[0]);
         return;
      }
 blog it

No comments: