Where can I find the IP address to connect to my RB750 (which is connected to the subnet of my Vodafone Station) from a server?
Thanks
You want to make a script on the router that gets the IP address of the router’s interface?
Since you posted in the Scripting section of the forum, that is my guess at least.
In one of my scripts I use this:{
:if ([:len [/interface find name=“Wan” disabled=no]] != 0) do={
:local wanIP “Wan interface has no IP address”
:if ([:len [/ip address find actual-interface=“Wan” disabled=no]] != 0) do={
:set wanIP [/ip address get [:pick [/ip address find interface=“Wan”] 0] address]
}
:put $wanIP
} else={
:put “No interface by that name”
}
}First I check if there is an interface named “Wan”, if there is check if it has an IP address, if it does get it.
But the basic way of getting the an interface’s IP address is just to use this::put [/ip address get [:pick [/ip address find interface=“Wan”] 0] address]Test it in the terminal.
Replace “Wan” with whatever the interface’s name is.
It then gets a little more complicated if you don’t want to find the interface based on it’s name.
So if this doesn’t help, you’ll have to give a bit more information about what it is you need and for what.
I have to try some PHP that connects to the router via IP address and in local with subnet IP address (192.168.5.1) it works … But from a server?
I have to try some PHP that connects to the router via IP address and in local with subnet IP address (192.168.5.1) it works … But from a server?
So it has nothing to do with making a script on the router?
If the router’s IP address is static (which router’s IP addresses normally are on a LAN) I don’t see a problem.
You have to give more information, maybe a diagram and some code examples of what you already have.
So far I have no idea what you are trying to do.
I’m trying this http://wiki.mikrotik.com/wiki/API_PHP_package#Print_router_logsVodafone Station
|
RB750 (192.168.5.1)
|
| |
PHP page
on localhost on
my PC$client = new RouterOS\Client(‘192.168.5.1’, ‘admin’, ‘password’);and it works…
but in this case
Vodafone Station
|
RB750 (192.168.5.1)
|
| |
my PC GUEST ___
|
|
|___PHP page on a server on the internet$client = new RouterOS\Client(‘???’, ‘admin’, ‘password’);Which IP address must I to use?
It’s a little easier to use MSPaint maybe, just saying.
Anyway if you are moving the PHP script to a website on the internet, then you need to use the WAN interface’s IP address.
But if you have a dynamic IP address from your ISP, you may be in trouble.
You could make your router report to the web server with it’s IP address every so often.
Here is a snippet from one of my scripts that does that:# Snippet from Deantwo’s RouterStatus script 2014-10-07
{
Get the Wan interface’s IP.
:local wanIP
:if ([:len [/interface find name=“Wan” disabled=no]] != 0) do={
:set wanIP “Wan%20interface%20has%20no%20IP%20address”
:if ([:len [/ip address find actual-interface=“Wan” disabled=no]] != 0) do={
:set wanIP [/ip address get [:pick [/ip address find interface=“Wan”] 0] address]
}
} else={
:set wanIP “No%20interface%20by%20that%20name”
}
:local urlParameters (“?wan-ip=” . $wanIP)
Define name of the file once it is downloaded. Not all that important.
:local filename “tempfile.html”
Delete the file if it exists already.
:if ([:len [/file find name=$filename]] != 0) do={
/file remove $filename
}
Define the full URL for the PHP script and concatenate the parameter ($urlParameters) string to it.
:local urlFull (“http://www.mikrotik.com/” . “ReportIP.php” . $urlParameters)
Show the full url for testing.
:put $urlFull
HTTP GET request is done here towards the webserver.
/tool fetch mode=http url=$urlFull dst-path=$filename
:delay 5
Delete the file when done. If run in the terminal, show the content of the file before deleting it.
:if ([:len [/file find name=$filename]] != 0) do={
:put [/file get [/file find name=$filename] contents]
/file remove $filename
}
}Then you can make a PHP script that saves that IP address in some way and use it in your other script.
The HTTP GET request will look like this:
http://www.mikrotik.com/ReportIP.php?wan-ip=10.0.0.1/24
Side note: Wish we were able to send HTTP POST messages.
I just need the ip address for a test. Is there a script that writes it in the terminal?
Thanks
yeah…
/ip address printUnless your router is behind another router that is.
But my router is behind another router …
http://lmgtfy.com/?q=what+is+my+ip
At least that will work if you are on the same LAN as the Mikrotik router.
Just be sure you have port-forwarded the correct ports on your gateway router.
how ?
Depends a lot on the router.
Check out this site: http://portforward.com/
and this?
http://wiki.mikrotik.com/wiki/Forwarding_a_port_to_an_internal_IP
Only if your gateway router is also a Mikrotik router.
how to compile it ??

how to compile it ??
Not sure what you mean by “compile it”.
As far as I understand you need to forward port 8728 to your Mikrotik router (192.168.5.1).
At least I am hoping your gateway router is on the same subnet as that IP address.
I can’t read the language in your picture, but like I said portforward.com should have all the information you need on how to setup portforwarding on your gateway router.
Read this page and follow the guide for your gateway router’s model:
http://portforward.com/english/routers/port_forwarding/routerindex.htm
If by “how to compile it”, you mean “how to change the setting”…
\
-
Use the previously mentioned
/ip address printto find out the WAN IP of your MikroTik router. We already know 192.168.5.1 is your LAN one, but your WAN is probably another IP in the 192.168.1.0/24 subnet (i.e. 192.168.1.2 or 192.168.3 or 192.168.1.7 or something else entirely). -
At that very page you have opened in the screenshot, write that IP in “Indlrlzzo locale”.
-
In “Protocollo”, select “TCP” if it’s not already selected.
-
In “Porta esterna” write 8728 in the first field. You could probably also fill the one under it with the same value. Either way, it shouldn’t make a difference.
-
In “Porta Interna”, write 8728 again.
-
Leave “Attlva” to “On”, if it’s not already.
-
You can write anything in “Servlzlo”. It’s just text that will let you know what’s that port used for. I’d suggest something like “RouterOS API” or something. Regardless, once you’re done with it all, click “Ok”.
-
(Maybe) Some routers require a reboot for such settings to take effect… So look for “Riavvio” or something similar (I don’t know Italian; I trust Google Translate when it’s telling me those are Italian words in that screenshot).
I had already tried, but I get the error: “Enter a port or range of ports valid”
Maybe it’s the wrong ip??
/ip address print
Flags: X - disabled, I - invalid, D - dynamic
ADDRESS NETWORK INTERFACE
0 X 192.168.23.1/24 192.168.23.0 bridge2
1 ;;; hotspot network
172.16.0.1/24 172.16.0.0 ether5-GUEST
2 192.168.5.1/24 192.168.5.0 ether2-TX
3 D 192.168.1.2/24 192.168.1.0 ether4_OUTSIDE
use ip cloud, in the advanced section set that the local address should be used.
your PHP code will happily take FQDN.