Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <net-snmp/net-snmp-config.h>
  2. #include <net-snmp/net-snmp-includes.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char ** argv)
  6. {
  7. struct snmp_session session;
  8. struct snmp_session *sess_handle;
  9. struct snmp_pdu *pdu;
  10. struct snmp_pdu *response;
  11. struct variable_list *vars;
  12.  
  13. oid id_oid[MAX_OID_LEN];
  14. oid serial_oid[MAX_OID_LEN];
  15.  
  16. size_t id_len = MAX_OID_LEN;
  17. size_t serial_len = MAX_OID_LEN;
  18.  
  19. int status;
  20.  
  21. struct tree *mib_tree;
  22.  
  23.  
  24.  
  25. init_snmp("APC Check");
  26.  
  27. snmp_sess_init(&session);
  28. session.version = SNMP_VERSION_1;
  29. session.community = "public";
  30. session.community_len = strlen(session.community);
  31. session.peername = "127.0.0.1";
  32. sess_handle = snmp_open(&session);
  33.  
  34. add_mibdir(".");
  35. mib_tree = read_mib("SNMPv2-MIB");
  36.  
  37. pdu = snmp_pdu_create(SNMP_MSG_GET);
  38.  
  39. read_objid("SNMPv2-MIB::sysDescr.0", id_oid, &id_len);
  40. snmp_add_null_var(pdu, id_oid, id_len);
  41.  
  42. status = snmp_synch_response(sess_handle, pdu, &response);
  43.  
  44. for(vars = response->variables; vars; vars = vars->next_variable)
  45. {
  46. print_value(vars->name, vars->name_length, vars);
  47. }
  48.  
  49. snmp_free_pdu(response);
  50. snmp_close(sess_handle);
  51.  
  52. return (0);
  53. }
  54.  
  55.  
  56.  
  57. # root@supertank:~# gcc -o snmp_get snmp_get.c $(net-snmp-config --cflags) $(net-snmp-config --libs) $(net-snmp-config --external-libs)
  58. root@supertank:~# ./snmp_get
  59. STRING: Linux supertank 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2 (2017-04-30) x86_64
  60.  
  61. # root@supertank:/etc/snmp# snmpget -mALL -v1 -cpublic 127.0.0.1 sysDescr.0
  62. SNMPv2-MIB::sysDescr.0 = STRING: Linux supertank 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2 (2017-04-30) x86_64
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement