IP和端口是打开还是PHP没有连接?

时间:2016-01-01 22:37:07

标签: php api mikrotik router-os

我正在尝试通过外部远程IP连接到MikroTik RouterOS,但我无法连接,因为我可以看到我可以通过Localhost成功连接到API,但无法通过我的站点上的托管文件进行连接。 !

这是指向文件的链接: http://huntedhunter.com/router-api/examples/example1.php

除了奇怪的是,我的IP上打开了8728端口,但它还没有连接...!

我正在使用此API进行连接: https://github.com/BenMenking/routeros-api

<pre>
<?php

require('../routeros_api.class.php');

$API = new RouterosAPI();

$API->debug = true;

if ($API->connect('39.33.4.164', 'test', 'test')) {


$ARRAY = $API->comm("/system/resource/print");


   $first = $ARRAY['0'];
$memperc = ($first['free-memory']/$first['total-memory']);
$hddperc = ($first['free-hdd-space']/$first['total-hdd-space']);
$mem = ($memperc*100);
$hdd = ($hddperc*100);
echo "Mikrotik RouterOs 4.16 Resources";
echo "<br />";
echo "<table width=550 border=0 align=center>";

echo "<tr><td>Platform, board name and Ros version is:</td><td>" . $first['platform'] . " - " . $first['board-name'] . " - "  . $first['version'] . " - " . $first['architecture-name'] . "</td></tr><br />";
echo "<tr><td>Cpu and available cores:</td><td>" . $first['cpu'] . " at " . $first['cpu-frequency'] . " Mhz with " . $first['cpu-count'] . " core(s) "  . "</td></tr><br />";
echo "<tr><td>Uptime is:</td><td>" . $first['uptime'] . " (hh/mm/ss)" . "</td></tr><br />";
echo "<tr><td>Cpu Load is:</td><td>" . $first['cpu-load'] . " %" . "</td></tr><br />";
echo "<tr><td>Total,free memory and memory % is:</td><td>" . $first['total-memory'] . "Kb - " . $first['free-memory'] . "Kb - " . number_format($mem,3) . "% </td></tr><br />";
echo "<tr><td>Total,free disk and disk % is:</td><td>" . $first['total-hdd-space'] . "Kb - " . $first['free-hdd-space'] . "Kb - " . number_format($hdd,3) . "% </td></tr><br />";
echo "<tr><td>Sectors (write,since reboot,bad blocks):</td><td>" . $first['write-sect-total'] . " - " . $first['write-sect-since-reboot'] . " - " . $first['bad-blocks'] . "% </td></tr><br />";

echo "</table>";

echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />Debug:";
echo "<br />";
   $API->disconnect();

}

?>
</pre>

1 个答案:

答案 0 :(得分:0)

首先检查是否在routeros中启用了api服务

[admin@mikrotik] > /ip service print
Flags: X - disabled, I - invalid 
 #   NAME      PORT ADDRESS                                        CERTIFICATE   
 0 XI telnet      23
 1 XI ftp         21
 2 XI www       8989
 3   ssh       22
 4 XI www-ssl    443                                                none          
 5 XI api       8728
 6   winbox    8291
 7 XI api-ssl   8729                                                none  

服务名称附近的XI标志-服务已停用

第二步检查防火墙过滤器表。链“输入”

您需要允许对api服务端口的输入访问。您可以首先在此答案中检查的api服务端口