Mikrotik Scripting: Get Interface IP

David Refoua picture David Refoua · Sep 8, 2016 · Viewed 7.8k times · Source

I want to get the local-address property of a pppoe-client interface, which is my public internet IP.

Assuming that the name of the interface is my-pppoe-out, what is the proper interface pppoe-client get command to use?


MikroTik Terminal Screenshot

I couldn't find anything useful in the official wiki for this.

Answer

Benoit PHILIPPON picture Benoit PHILIPPON · Sep 8, 2016

You can't get the IP directly on the command-line, you must use a script to do this.

:local ip [/ip address get [find interface="pppoe-out1"] address ];
:put "IP: $ip"

Then you can do whatever you want with the variable $ip (here i just write it in the console) like updating a dyndns, etc.

To use this script, either copypaste it in a file like "ip.rsc" and then type "import ip.rsc" to execute it, or put it on a routerOS script (/system script add ..).