I’ve made a very simple php to show registered clients, their MAC, signal and interface connected to.
Improvments will come, I hope ![]()
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>