Community discussions

MikroTik App
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Where can I find the IP address ...

Sun Oct 05, 2014 2:00 am

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
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Mon Oct 06, 2014 4:11 pm

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.
Last edited by Deantwo on Tue Oct 07, 2014 4:42 pm, edited 1 time in total.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Mon Oct 06, 2014 4:30 pm

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?
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Mon Oct 06, 2014 4:33 pm

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?
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Tue Oct 07, 2014 11:50 am

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.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Tue Oct 07, 2014 4:15 pm

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?
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Tue Oct 07, 2014 4:37 pm

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.
Last edited by Deantwo on Tue Jun 28, 2016 12:16 pm, edited 1 time in total.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Tue Oct 07, 2014 6:27 pm

I just need the ip address for a test. Is there a script that writes it in the terminal?
Thanks
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Tue Oct 07, 2014 6:39 pm

yeah...

ros code

/ip address print
Unless your router is behind another router that is.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Tue Oct 07, 2014 6:47 pm

But my router is behind another router ...
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Tue Oct 07, 2014 6:52 pm

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.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Tue Oct 07, 2014 7:00 pm

Just be sure you have port-forwarded the correct ports on your gateway router.
how ?
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Tue Oct 07, 2014 7:06 pm

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/
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Tue Oct 07, 2014 7:30 pm

 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Tue Oct 07, 2014 7:42 pm

Only if your gateway router is also a Mikrotik router.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Wed Oct 08, 2014 1:22 pm

how to compile it ??
You do not have the required permissions to view the files attached to this post.
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Wed Oct 08, 2014 3:30 pm

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
Last edited by Deantwo on Fri Dec 18, 2015 10:11 am, edited 1 time in total.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

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

Wed Oct 08, 2014 3:48 pm

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).
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Wed Oct 08, 2014 4:15 pm

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
>
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

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

Wed Oct 08, 2014 4:20 pm

use ip cloud, in the advanced section set that the local address should be used.
your PHP code will happily take FQDN.
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

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

Wed Oct 08, 2014 4:21 pm

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.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Wed Oct 08, 2014 5:16 pm

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
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

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

Wed Oct 08, 2014 5:23 pm

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?
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Wed Oct 08, 2014 5:48 pm

sure
You do not have the required permissions to view the files attached to this post.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

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

Wed Oct 08, 2014 5:53 pm

Specify 192.168.1.2 as the IP, not 192.168.5.1.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Wed Oct 08, 2014 6:06 pm

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."
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

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

Wed Oct 08, 2014 6:15 pm

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.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Wed Oct 08, 2014 6:36 pm

It says:
Your IP Address Is: 2.34.107.153
Proxy: 172.16.0.1 2.34.107.153 1.1 (Mikrotik HttpProxy)
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

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

Wed Oct 08, 2014 6:39 pm

2.34.107.153

That should probably cut it.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

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

Wed Oct 08, 2014 7:00 pm

It works! Thank you all!
 
User avatar
aacable
Member
Member
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

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

Wed Apr 10, 2019 12:01 pm

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