Git Product home page Git Product logo

phpsnmp's Introduction

#phpSNMP

phpSNMP is an SNMP implementation based on libsnmp, which is written in Python. It has been ported to 100% pure PHP.

Why not just use the SNMP extension?

The data return from the SNMP extension is not uniform accross platforms with different MIBs installed. The SNMP extension does not support traps. The SNMP extension does not support parallel gets. The SNMP extension does not support bulk gets. The SNMP extension results in semi-frequent core dumps on FreeBSD (I think it has something to do with threads). The SNMP extension requires building yet another extension into PHP.

Usage

<?php
  ini_set('memory_limit', '256M');

  require('snmp.php');

  $oid = '.1.3.6.1.2.1.69.1.1.3';
  $oid = '.1.3.6.1.6.3.15.1.1.4.0';

  // test the oid_format function
  $z = oid_format($oid, OID_TEXT);
  $zz = oid_format($z, OID_NUMERIC);
  echo "$oid => $z => $zz\n";

  $ip = '172.16.0.116'; 		// ip address or hostname
  $ips = array($ip, '172.16.0.64');	// array of ip addresses or hostnames
  $community = 'public';		// community string
  $oid = '.1.3.6.1.2.1.1';		// only numerical oids are supported
  $oids = array('.1.3.6.1.2.1.1.1', '.1.3.6.1.2.1.1.3');

  $snmp = new snmp();

  $snmp->version = SNMP_VERSION_2;

  print_r($snmp->walk($ip, $oid, ['community' => $community]));
  print_r($snmp->multi_walk($ips, $oid, ['community' => $community]));


  $snmp->version = SNMP_VERSION_3;
  print_r($snmp->get('localhost', '.1.3.6.1.2.1.1.3.0', array('v3_flags'=>SNMP_AUTH_PRIV, 'v3_user'=>'v3user',
                                                              'v3_auth'=>'authpassword', 'v3_priv'=>'privpassword')));

  // get system uptime
  print_r($snmp->get($ip, '.1.3.6.1.2.1.1.3.0', ['community' => $community]));
  print_r($snmp->multi_get($ips, '.1.3.6.1.2.1.1.3.0', ['community' => $community]));

  // bulk get
  print_r($snmp->bulk_get($ip, $oids));

  // reset cable modem(s)
  $oid = '.1.3.6.1.3.83.1.1.4.0.1.1.3.0';
  $snmp->set($ip, $oid, 1, 'i', ['community' => 'private']);
  $snmp->multi_set($ips, $oid, 1, 'i', ['community' => 'private']);

  // send a trap
  $ip = '123.45.12.3';
  $community = 'public';
  $varbind = $snmp->build_varbind('.1.3.6.1.3.83.1.1.4.1', 17, 'i');
  $enterprise = '.1.3.6.1.3.83.1.1.4.0.1.1.3.0';
  $agent = '127.0.0.1';
  $trap_type = TRAP_LINKUP;
  $specific_trap_type = 2;
  $uptime = 123;

  $snmp->trap($ip, $community, $varbind, $enterprise, $agent, $trap_type, $specific_trap_type, $uptime);
?>

phpsnmp's People

Contributors

brexis avatar

Stargazers

Christopher Hubbard avatar Robson F. Ramaldes avatar Anton Zheltyshev avatar Francisco Ventura avatar Rihards Mantejs avatar Guilherme Sehn avatar PM2D avatar 尘埃 avatar Piwi avatar Cees-Jan Kiewiet avatar

Watchers

PM2D avatar James Cloos avatar  avatar Rihards Mantejs avatar  avatar

phpsnmp's Issues

PHP 7.1: Deprecated Mcrypt

Hello
mcrypt_module_open is deprecated.
I do not want to use "@" because i will update my php to v7.2 soon
and i am looking for another good solution how to fix it
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.