-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting user MAC address resolves in error #24
Comments
Response::getProperty() exists since the latest released version, i.e. 1.0.0b5. If you're using an older version, then yes, you're not going to have it. But I'm guessing you only "just" downloaded it, given your previous issue, so I don't see how could this be... I'll double check the example and the client (not today though...), but in the meantime, one possible workaround might be to first get the first response explicitly with $client->sendSync($printRequest)->current()->getProperty('mac-address') or if even that doesn't work, see what methods you do have with: var_dump(get_class_methods($client->sendSync($printRequest)->current())); |
When using I got this error: And with I got this error:
|
Yeah, you're definitely using an older version. I highly recommend you upgrade to the latest released version (see the releases page). |
I've downloaded the latest version 1.0.0b5, however it still doesn't seem to work. With: I get: The other two: |
if (null !== $mac) { checks that, and shows the error message. And as the message says, perhaps the IP you're accessing the web page with is not in the ARP table? Do a var_dump($_SERVER['REMOTE_ADDR']); and see if that IP is present in the ARP table. |
Its null, not false sorry. Just in case there is something wrong with the condition, I am
I'll do a |
In your modified code, |
This way it does establish a connection with the router, with the connection test script. I should try something like this then |
In that case, yeah, the script will always be false, because the router's IP is not part of the ARP table. You need to modify the line RouterOS\Query::where('address', $_SERVER['REMOTE_ADDR']) to use something other than |
So how do you propose I get the IP so I can have multiple routers opening this page, with the same login info just different IPs? The IPs on some of these routers will be dynamic...so it is important that it does that. What we need is to grab the Mac of the device that is accessing this page/script—therefore identify the user, so we can display that user some relevant info from a DB. |
That depends on a lot of factors about the router configuration. If the routers uses hotspot, and you have disabled anonymous proxy, you can look for the Another way, which works for almost every other scenario is to lookup the |
So either:
or this then:
Or did you mean |
Not quite that simple I'm afraid... I had written something like that at one point, but since deleted it, as it turned out I could use I could get back to you with working code in a few days, but rather than wait for me, I suggest you examine in detail the |
You mentioned something about hotspot above. It should "hopefully" work regardless whether its a hotspot or not. I'll try, thought I doubt I'll solve it...a total newb with RouterOS and MikroTik in general. If I don't post anything here, and if you manage to solve it please share...it would definitely be of great help as it's the core of my project. |
Well... sorry for having taken so long... I finally found a continious stretch of free time to fully test this out... And this is what I ended up with: $util = new RouterOS\Util(
$client = new RouterOS\Client($_SERVER['REMOTE_ADDR'], 'admin', 'password')
);
$ip = isset($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : strstr(
$util->setMenu('/ip firewall connection')->get(
$util->find(
RouterOS\Query::where('protocol', 'tcp')
->andWhere('reply-dst-address', $_SERVER['REMOTE_ADDR'] . ':' . $_SERVER['REMOTE_PORT'])
->andWhere('reply-src-address', (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']) . ':' . $_SERVER['SERVER_PORT'])
),
'src-address'
),
':',
true
);
$mac = $util->setMenu('/ip arp')->get($util->find(RouterOS\Query::where('address', $ip)), 'mac-address'); The key being the Note that this only works for one level NAT (RouterOS has a public IP). A double level NAT won't work unless you setup the router and web server be inside a common VPN (so that they can see each other's IPs directly). |
Hello @boenrobot , |
The web server also needs to be a member of the VPN, and (more importantly) be accessed through that VPN IP. I understand you might want to have your web server ALSO be accessed via a public IP... But in that case, you'd want to dedicate a subdomain to which the A/AAAA record will be the VPN IP. |
In webserver runs a VPN Client. Server is already connected to VPN. I can ping server from mikrotik and reverse with VPN ips. |
But what about when you open up the PHP page from an end user device? In the browser, are you opening |
It is an external hotspot page. User hits the router hotspot, router hotspot redirects user to external hotspot page and external hotspot redirects user back to router hotspot. The problem is that external hotspot is already to a subdomain and i need it to be accessible from outside for other apis connections but also from mikrotik api for resolving mac address at the same time. I already added a subdomain name to hotspot with the ip that router gets from vpn server and post requests are fine. Api connection is fine. But no way to find users local ip. I even tried to read a file which prints the ip but with no hope. |
A redirect is OK, but the PHP page the user is redirected to needs to use a subdomain that resolves to the VPN IP of the web server (if not the VPN IP itself, without a DNS name). The external web server may be configured to be accessible from multiple IPs and (sub)domains. Certain pages (e.g. API related ones) can be configured to only open from certain subdomains, and certain other pages (e.g. those that need to also be accessible by 3rd parties, but otherwise don't interact with the router) may be configured to be accessible from all subdomains. It's just that hotspot users need to use the VPN IP, or a subdomain that resolves to that IP.
Add a domain name to hotspot with the IP that the external web server gets from the VPN server, and redirect to that from hotspot. |
Hi @boenrobot again. I have done what you told me to do. Now all users who are connected to mikrotik when they visit the external hotspot page they are doing it with the VPN ip that the server gets from the VPN network. The external hotspot page resolves via the web server vpn ip and not the public one. Although when i use $_SERVER['REMOTE_ADDR'] i still see user public ip and not the local one. |
To be perfectly honest, I've never tested any of that code through a VPN, so I wasn't sure if Upon some googling right now, I guess when using a VPN, you could use What does |
"REMOTE_ADDR" => "..."public user ip Only these variables with ips or ports |
The only possible issue I'm seeing is that the traffic isn't going through the VPN for some reason, but is routed over the real IP. This could happen if the client's DNS server is not your router for example (which is why I suggested you add a new subdomain at the web server's DNS server; where your public domain's IP is defined), or if you're reusing a pre-existing subdomain, and the DNS cache points to the public IP. Are you sure the VPN IP is used? If from a hotspot client you call |
I get the VPN ip, i use another mikrotik for vpn server not the same mikrotik for hotspot |
What type of VPN are you using? OpenVPN? At this point, the only way I could potentially help is by actually setting up a VPN in a GNS3 lab, and perhaps afterwards comparing my experience/settings with those in your network. |
We are using this script that we found in the Wiki page:
However, we get the following error:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'PEAR2\Net\RouterOS\Response' does not have a method 'getProperty' in/home/admin/web/domain/public_html/PEAR2/Net/RouterOS/ResponseCollection.php on line 356
Has there been some kind of an update, and we are just using an older version of the script?
So far, we are able to establish a connection.
Thanks.
The text was updated successfully, but these errors were encountered: