Page 1 of 1

Where can I find the IP address ...

Posted: Sun Oct 05, 2014 2:00 am
by MBAGA
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

Re: Where can I find the IP address ...

Posted: Mon Oct 06, 2014 4:11 pm
by Deantwo
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:

ros code

{
    :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:

ros code

: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.

Re: Where can I find the IP address ...

Posted: Mon Oct 06, 2014 4:30 pm
by MBAGA
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?

Re: Where can I find the IP address ...

Posted: Mon Oct 06, 2014 4:33 pm
by MBAGA
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?

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 11:50 am
by Deantwo
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.

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 4:15 pm
by MBAGA
I'm trying this http://wiki.mikrotik.com/wiki/API_PHP_p ... outer_logs

html code

Vodafone Station
		   |
	      RB750 (192.168.5.1)
	   _____|_____
	  |	            |
   PHP page
   on localhost on
   my PC

php code

$client = new RouterOS\Client('192.168.5.1', 'admin', 'password');
and it works...

but in this case

html code

Vodafone Station
		   |
	      RB750 (192.168.5.1)
	   _____|_____
	  |	            |
   my PC	      GUEST ___
                          |
                          |
                          |___PHP page on a server on the internet

php code

$client = new RouterOS\Client('?????', 'admin', 'password');
Which IP address must I to use?

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 4:37 pm
by Deantwo
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:

ros code

# 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.

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 6:27 pm
by MBAGA
I just need the ip address for a test. Is there a script that writes it in the terminal?
Thanks

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 6:39 pm
by Deantwo
yeah...

ros code

/ip address print
Unless your router is behind another router that is.

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 6:47 pm
by MBAGA
But my router is behind another router ...

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 6:52 pm
by Deantwo
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.

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 7:00 pm
by MBAGA
Just be sure you have port-forwarded the correct ports on your gateway router.
how ?

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 7:06 pm
by Deantwo
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/

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 7:30 pm
by MBAGA

Re: Where can I find the IP address ...

Posted: Tue Oct 07, 2014 7:42 pm
by Deantwo
Only if your gateway router is also a Mikrotik router.

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 1:22 pm
by MBAGA
how to compile it ??

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 3:30 pm
by Deantwo
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/ ... rindex.htm

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 3:48 pm
by boen_robot
If by "how to compile it", you mean "how to change the setting"...


1. Use the previously mentioned

ros code

/ip address print
to 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).

2. At that very page you have opened in the screenshot, write that IP in "Indlrlzzo locale".
3. In "Protocollo", select "TCP" if it's not already selected.
4. 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.
5. In "Porta Interna", write 8728 again.
6. Leave "Attlva" to "On", if it's not already.
7. 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".

8. (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).

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 4:15 pm
by MBAGA
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
>

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 4:20 pm
by janisk
use ip cloud, in the advanced section set that the local address should be used.
your PHP code will happily take FQDN.

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 4:21 pm
by Deantwo
I had already tried, but I get the error: "Enter a port or range of ports valid"
It means you didn't enter a port number in one of the required fields.
"Porta esterna" has two boxes, try adding the port number to both of them.
Maybe take a screenshot of what you have entered into the window.
> /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                                                                                                                       
>
And I think the IP address you need to enter is "192.168.1.2".
Because it is the only one you have gotten through DHCP.

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 5:16 pm
by MBAGA
use ip cloud, in the advanced section set that the local address should be used.
your PHP code will happily take FQDN.
but This http://wiki.mikrotik.com/wiki/Manual:IP/Cloud Applies to RouterOS: v6.14+
"Porta esterna" has two boxes, try adding the port number to both of them.
And I think the IP address you need to enter is "192.168.1.2".
I have tried both without success

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 5:23 pm
by boen_robot
use ip cloud, in the advanced section set that the local address should be used.
your PHP code will happily take FQDN.
That wouldn't help if the outside router doesn't forward the port.
"Porta esterna" has two boxes, try adding the port number to both of them.
And I think the IP address you need to enter is "192.168.1.2".
I have tried both without success
Forgive me for not trusting you, but... A screenshot of right before you press OK, and another one with what the router shows right after please?

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 5:48 pm
by MBAGA
sure

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 5:53 pm
by boen_robot
Specify 192.168.1.2 as the IP, not 192.168.5.1.

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 6:06 pm
by MBAGA
Specify 192.168.1.2 as the IP, not 192.168.5.1.
ok now from ether5-GUEST I open logs.php but I get "Unable to connect to RouterOS."

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 6:15 pm
by boen_robot
The IP you write in PHP must be your public one.

Open "wimi.com" from the guest, and see what IP you see there. Write that IP in PHP.

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 6:36 pm
by MBAGA
It says:
Your IP Address Is: 2.34.107.153
Proxy: 172.16.0.1 2.34.107.153 1.1 (Mikrotik HttpProxy)

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 6:39 pm
by boen_robot
2.34.107.153

That should probably cut it.

Re: Where can I find the IP address ...

Posted: Wed Oct 08, 2014 7:00 pm
by MBAGA
It works! Thank you all!

Re: Where can I find the IP address ...

Posted: Wed Apr 10, 2019 12:01 pm
by aacable
Basic way of getting the an interface's IP address is just to use this:

ros code

:put [/ip address get [:pick [/ip address find interface="Wan"] 0] address][/code]
Replace "Wan" with whatever the interface's name is.
This saved my day as well. Thank you