I’m trying to get some DDNS updater scripts working, and have come across a common issue. Where there is code such as this:
:local currentIP [/ip address get [find interface=“$inetinterface” disabled=no] address]
This doesn’t work for me, as my interface has two IP addresses (one for the WAN, another for the cable modem management interface), so find interface is getting an array.
Is there a common way of getting whichever of these addresses is the public routable IP instead of the internal one?
Assuming you have configured at least one DNS server on your RouterBOARD, you may use this:
local currWANAddress [toip [resolve myip.opendns.com server=resolver1.opendns.com]]
It will give you the WAN address of your current default gateway (least distance 0.0.0.0/0 route). Source
(You can use the provision and dyndns modules of RouterSCRIPTS as well - they’re pretty reliable)
From what I do read. He need to get the public IP, the one that its routed to the internt, so that he can make a script to update for example no-ip.com site with his IP, so that he can reach his Router using a public DNS service form other side of the internet.
If you ask to resolve myip.opendns.com, you already has updated the opendns.com with your IP. He has not done that yet.
When you resolve myip.opendns.com you also need to supply server=resolver1.opendns.com to the command.
sebastia is correct that this is a special feature which replies back to you, with your WAN IP address.
This feature can be used regardless of which Dynamic DNS service you’re using. We assume that this has been dealt with, as it’s out of scope for this topic.
This feature does not update your Dynamic DNS service, as that requires credentials to do so (explained right below).
The script must then do a fetch (HTTP POST Request) to the corresponding API of the Dynamic DNS (i.e. NoIP, DynDNS) service that is being used, with the:
Username
Password
Hostname
WAN IP address (that we just determined with said resolve command).
The problem was, as the user described it, that he had no way to determine his WAN/Internet address - and the excerpt which I supplied does exactly that.