If everyone has the same problem I got the solution:
First get the real IP of the user's device based on $_SERVER variables:
use PEAR2\Net\RouterOS;
function get_real_ip(){
$client = new RouterOS\Client($_SERVER['REMOTE_ADDR'], 'username', 'password');
$request = new RouterOS\Request('/ip/firewall/connection/print');
$query = RouterOS\Query::where('reply-dst-address', $_SERVER['REMOTE_ADDR'].':'.$_SERVER['REMOTE_PORT']);
$request->setArgument('.proplist', 'src-address');
$request->setQuery($query);
$responses = $client->sendSync($request);
foreach ($responses as $response) {
foreach ($response as $name => $value) {
$parts = explode(":", $value);
$real_ip = $parts[0];
}
}
if ($real_ip) {
return $real_ip;
} else {
return false;
}
}
And then get its mac address:
function get_mac($real_ip){
$client = new RouterOS\Client($_SERVER['REMOTE_ADDR'], 'username', 'password');
$request = new RouterOS\Request('/ip/arp/print');
$query = RouterOS\Query::where('address', $real_ip);
$request->setArgument('.proplist', 'mac-address');
$request->setQuery($query);
$responses = $client->sendSync($request);
foreach ($responses as $response) {
foreach ($response as $name => $value) {
//echo "{$value}\n";
$mac = $value;
}
}
if ($mac) {
return $mac;
} else {
return false;
}
}
You can get it in one step:
$mac = get_mac(get_real_ip());
If you need the router name:
function get_router_name(){
$util = new RouterOS\Util(
$client = new RouterOS\Client($_SERVER['REMOTE_ADDR'], 'username', 'password')
);
$util->setMenu('/system identity');
$router_name = $util->get(null, 'name');
return $router_name;
}
I hope this helps someone.
Dont forget to change username and password in connection parameters