Web linktest for RouterOS 2.8

I’ve made a very simple php to show registered clients, their MAC, signal and interface connected to.

Improvments will come, I hope :wink:

Put the code in a php-file somewhere in your apache web-directory. Make sure that snmpwalk and snmpget is installed on your system, snmp is enabled in your RouterOS, and that $snmpwalk og $snmpget is correctly set(whereis snmpwalk).

<?php
/*
TODO:
- Use apache snmp module
- SQL table over MAC-adresses
- Automatic refresh
- Selection of single client
- When client is selected, produce trafic to him(ping/etc) so that signal is updated more often
- Error messages
*/

/*
Tested on Debian Sarge with following packages:
- Apache 1.3.26-0woody6
- PHP 4.1.2-7.0.1
- net-snmp 5.1.1-2
*/

/* set these values to match your enviroment. */
$snmpwalk = "/usr/bin/snmpwalk";
$snmpget = "/usr/bin/snmpget";
?>
<html>
<head>
<title>Mikrotik linktest</title>
</head>
<body>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post">
IP Mikrotik AP:
<input type="text" maxlength="15" name="ip" value="<?php echo $_POST['ip']; ?>">
SNMP Community:
<input type="password" name="password" value="<?php echo $_POST['password']; ?>">
<input type="submit" name="submitted" value="Link test!">
</form>
<?php
if ($_POST['submitted']) {
 /* Open tmp file - open snmp connection - bla bla bla */
 /* Code/ideas stealed from freeradius-dialupadmin. */
 $server = escapeshellcmd($_POST['ip']);
 $community = escapeshellcmd($_POST['password']);
 $tmp_file = tempnam('/tmp/','LT');
 $command_clients = $snmpwalk . " -v 1 -c $community $server .1.3.6.1.4.1.14988.1.1.1.2.1.3" . ' >' . $tmp_file;
 $filepointer = popen("$command_clients","w");
 pclose($filepointer);
 $reply = file($tmp_file);
 unlink($tmp_file);
 $int = 0;
 echo <<< EOM
<table border="1">
<tr><th>Client</th><th>MAC</th><th>signal(dBm)</th><th>Interface</th></tr>
EOM;
;
 foreach ($reply as $reply_line) {
  $int++;
  $oid_splitted = explode('.',$reply_line);
  echo "<tr><td>$int</td><td>" . dechex($oid_splitted[8]) . ':' .
        dechex($oid_splitted[9]) . ':' . dechex($oid_splitted[10]) . ':' . dechex($oid_splitted[11]) . ':' . dechex($oid_splitted[12]) . ':' .
        dechex($oid_splitted[13]) .
        "</td><td>";
  $dbm = explode (" ", $oid_splitted[14]);
  $command_interface = "$snmpget -v 1 -c $community $server ifDescr.$dbm[0]";
  $interface = exec($command_interface);
  $interface = explode(" ", $interface);
  $interface = $interface[3];
  echo "$dbm[3]</td><td>$interface</td></tr>";
  }
 echo '</table>';
 }
?>
</body>
</html>

Well done mate, I will try this for sure, thx…

I’ve been working a bit more on this. The goal is to integrate a customer database(freeradius-dialupadmin or home-made sql) with mikrotik accesspoints. This would ease the administration a lot.

Updated web linktest interface can be download here: http://jumper.biatches.org/~arve/mikrotik/

More to come :slight_smile:

snmpwalk in php returns OID on 1 of my debians, but doesn’t on the other. This will make problems when we try to get out the MAC from OID.

v0.03 fixes this(using snmpwalk through exec).

Give me a feedback if it works for you too.

Now the demo at http://jumper.biatches.org/~arve/mikrotik/demo/ works.

That’s cool.. nice work. damn i need to get a book on PHP! :slight_smile:

I’ve read this one: http://www.amazon.com/exec/obidos/tg/detail/-/0764549553/002-9557920-0064837?v=glance

http://www.php.net does also have exelent documentation.

I’ve added more detailed clients info.

Current version is 0.04 :wink:

Good work…

If Mikrotik has both tx and rx signal-strenght as SNMP output …

Correct me if I’m wrong, but I think the signal is rx from the device you are measuring on since the 802.11 standard doesn’t share signal strength between AP and client. If you got a Mikrotik client, try to enable SNMP on it, and use this linktest against the client. Don’t know how I could make a workaround for this in PHP.

Maybe I’ll make a ssh variant, instead of SNMP. Then we could show more info, which isn’t available through SNMP. And also use the “/ip neighbor” to solve this rx/tx signal strength problem.