0

我正在尝试通过 PHP 与 Mikrotik Router OS 通信,如下所示

 private function openSocket(): void
    {
        $options = ['ssl' => $this->config('ssl_options')];
        $context = stream_context_create($options);
        $proto = $this->config('ssl') ? 'ssl://' : '';
        $socket = @stream_socket_client(
            $proto . $this->config('host') . ':' . $this->config('port'),
            $this->socket_err_num,
            $this->socket_err_str,
            $this->config('timeout'),
            STREAM_CLIENT_CONNECT,
            $context
        );
        if ($socket === false) {
            throw new ConnectException('Unable to establish socket session, ' . $this->socket_err_str);
        }
        stream_set_timeout($socket, $this->config('timeout'));
        $this->setSocket($socket);
    }

在这里, PORT 是其中之一 public const PORT = 8728; public const PORT_SSL = 8729;。和 IP 地址是192.168.0.1

连接在本地主机上完美运行。

现在,当我尝试从托管在在线服务器上的 php 脚本访问 RouterOS 时,我不断地Unable to establish socket session, No route to host从 php 脚本中得到错误。

请问,我该如何解决这个问题。

任何帮助将不胜感激。

4

0 回答 0