Connecting to Mikrotik router remotely from application running on the server through API
Posted: Sat May 07, 2022 5:46 am
Let me start by saying that I am not a networking expert but more of a software developer. I have been working on a web application to manage WIFI hotspot users using the Mikrotik API interface.
This is how the application works:
When a user connects to the hotspot, they are redirected to the hotspot plans page where they are asked to choose a hotspot plan and pay for it. After they have paid for that plan, the application automatically creates a user on the user-manager database using the details they provided and activates their profile so that the user can access the internet(I am using the radius server to authenticate users). The application works very well on my local computer using localhost.
My Problem
The problem arises when I host the application on the server(online). When I try connecting to the router from the online application, the connection does not go through. I get an error saying "Error connecting to RouterOS".
How I am doing it
The same code is working on localhost. I did some research and someone suggested that I should use the public IP address but it doesn't work with the public IP address as well.
The web application is hosted on a VPS running ubuntu os. Could someone suggest to me what I am supposed to do or what I am doing wrongly here?
Thank you.
This is how the application works:
When a user connects to the hotspot, they are redirected to the hotspot plans page where they are asked to choose a hotspot plan and pay for it. After they have paid for that plan, the application automatically creates a user on the user-manager database using the details they provided and activates their profile so that the user can access the internet(I am using the radius server to authenticate users). The application works very well on my local computer using localhost.
My Problem
The problem arises when I host the application on the server(online). When I try connecting to the router from the online application, the connection does not go through. I get an error saying "Error connecting to RouterOS".
How I am doing it
Code: Select all
use PEAR2\Net\RouterOS;
//connectng to the router
$client = new RouterOS\Client('198.162.164.49', 'admin', 'password');
//interacting with the router
The web application is hosted on a VPS running ubuntu os. Could someone suggest to me what I am supposed to do or what I am doing wrongly here?
Thank you.