modified on 21 July 2010 at 07:21 ••• 33,350 views


From MikroTik Wiki

Jump to: navigation, search

This small example is a PHP script, that uses SNMP to read signal strength values from wireless registration table and publish on web page. This example can be quickly transformed to read other values available for SNMP. To use scripts you need Mikrotik RouterOS, tested for version 2.9.xx (not yet for 3.0), PHP version 4 or 5, Web server (Apache, IIS). Configure Apache, and PHP only thing that needs attention is enabled snmp extension for PHP. In Windows in php.ini section Windows Extensions uncomment line

extension=php_snmp.dll . 

Enable snmp on Mikrotik, and if needed, unblock UDP port 161. Copy scripts to WEB folder. Open index.php find line

$ip="hostname";    //Change IP to your host names, address
$mask_mac=false;        //Use to mask MAC adress (true / false );

Replace hostname with IP address of Mikrotik, if you don’t want to see complete MAC address change false to true and now open the page in browser. You now see MAC address and signal strength. Page is auto refreshed every 10 seconds and reads values from SNMP.

The PHP code, to be saved as a .php file:

<!-- /*******************************************************************
 * Mikrotik SNMP signal reader by Perica Nikolic
 * Contact
 * This copyright notice MUST stay intact for use.
 * This is free software; you can redistribute it and/or modify.
 * This script is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");
	<link href="stil.css" type="text/css" rel="stylesheet" />	
<table align="center">
<caption class="maintable">Mikrotik signal list</caption>
<th class="maintable">MAC</th>
<th class="maintable">Signal <br>strenght(dBm)</th>

$ip="hostname or IP";    //Change IP to your host names, address
$mask_mac=false;        //Use to mask MAC adress (true / false );

$tx_bytes_snmp = snmpwalkoid("$ip", "public", ".");  

if (is_array($tx_bytes_snmp))

		foreach ($tx_bytes_snmp as $indexOID => $rssi)
			for ($counter=2;$counter<8;$counter++)
				$temp=sprintf('%02x', $oidarray[$end_num-$counter]);
				if (($counter <5) && $mask_mac)
				else if ($counter==7)
			$mac_oiu = substr(str_replace(":","-",$mac),0,8);
			<tr><td class="maincolum"><a href="<?php echo ($mac_oiu); ?>" target="_blank" class="tablelink"><?php echo ($mac); ?></a></td>
			<td class="maincolum" align="center"><?php echo ($rssi); ?></td>
	<tr><td colspan="2" class="warning">Please check SNMP settings and IP address</td></tr>