PHP Api PEAR2_Net_RouterOS, local ip

Hi everyone,
I need to get users mac address but to get their mac address i need to get their local ip (192…).
Note that i have tried many php scripts as i am php developer and all return public ip except when i use curl from local server.
So how i can retrieve user local ip from external server using PEAR2_Net_RouterOS;
I am connecting to routerOS but i can’t find a way to get user local ip. I even tried to read a file where outputs $(ip) but this can’t happen cause it returns the variable as text and not the value.

Thanks in regards

See this issue in GitHub for a sample code that does just that.

Note that the web server needs to be able to reach the router without a double NAT in play, i.e. the router’s WAN IP must be the public IP, or alternatively, you need to setup a VPN between the web server and router, and connect through it.

I have already seen that many times since i am looking for a solution for a couple of days before i post here. I plugged Mikrotik after providers router with static ip and i made a port forward for the ports of the api and for http requests and i accepted incoming connections to the mikrotik. Now every time i try to view my ip i always view ip from providers router and not from mikrotik. Is VPN the only solution? Are there any commands in routerOS to view my local ip?

Yes. A VPN of any sort is the only solution for this. Sorry.

The problem is that from the router’s point of view, you can have multiple WAN interfaces (e.g. load balancing and/or as a fallback), and any one of them could potentially be reachable or not from the web server. There’s no way for the router to know for sure where it is reached from.

If YOU know for a fact, then you can be explicit when calling “/ip address get”, but that doesn’t help your REAL goal. The real problem is the provider’s router is doing a NAT, and you don’t have access to its connections table. If the provider’s router was a MikroTik router and you had some way of checking its “/ip firewall connections” list, then you could simply apply the procedure twice - lookup the local router IP and reply port from the provider’s router, and then lookup the local IP from the local router.

Thank you very much.
I leave this topic open in case i encounter any problems with the vpn.

Hi again @boen_robot ,

We have managed to setup a vpn network. Mikrotik and VPS server are all connected to VPN server. I can connect to mikrotik api but i can’t find a way to get the local ip so i can get the mac address. Every time i use the server variable in php i always get my public ip and not the local one. $_SERVER[‘REMOTE_ADDR’] returns my public ip, $_SERVER[‘X_FORWARDED_FOR’] not even exists and $_SERVER[‘SERVER_ADDR’] returns the ip of the VPS. I only connect to Api with hardcode ip but i cannot hardcode users ip. Any solution to this?