用于php IP Bindings的Mikrotik api

时间:2017-03-15 17:48:19

标签: php mikrotik

所以我有这个代码

<?php
require('routeros_api.class.php');
include 'include/global.php';
include 'include/function.php';

$username = $_GET['user'];

$sql    = "SELECT user_macaddress FROM demo_user WHERE user_name='".$username."'";
$result1    = mysql_query($sql);
$mac        = mysql_fetch_array($result1);

$API = new RouterosAPI();

$API->debug = true;

if ($API->connect('192.168.88.1', 'admin', '1')) {

    $API->write('/ip/hotspot/ip-binding/add',false);
    $API->write('=type=bypassed',false);
    $API->write("=mac-address='".$mac."'",true);
    $READ = $API->read();
    $API->disconnect();
    ob_clean();
    header("location:http://google.com");

}


?>

我使用mikrotik的php api自动添加mac地址,但mac地址从未显示在我的winbox中的ip绑定中。你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

不要将MAC地址包装到单引号中。使用此代码:

$API->write('/ip/hotspot/ip-binding/add',false);
$API->write('=type=bypassed',false);
$API->write('=mac-address='.$mac,true);

MAC可以采用以下格式:xx:xx:xx:xx:xx:xxxxxxxxxxxxxx