Community discussions

MikroTik App
 
wil
just joined
Topic Author
Posts: 10
Joined: Wed Jun 04, 2014 4:42 pm

getting IP of DSL interface

Wed Jan 04, 2017 4:50 pm

Hi,

I use a script to update the IP at my DDNS provider. The router has a DSL line (pppoe) and a 3G fallback. Only the IP of the DSL line should be used to update DDNS. So I did this:

:foreach ipv4addr in=[/ip address get [find interface=dsl-line] address] do= {
:local newaddr [:pick $ipv4addr 0 [:find $ipv4addr "/"] ]
<code for updating DDNS according to $newaddr>

However sometimes the code sends IP of the 3G interface instead. This might have to do something with the DSL connection being reestablished. The idea behind the foreach loop was that I don't send DDNS updates as long as I don't have an IP on the DSL interface. Because the loop does not work reliable I replaced it with the following code which worked so far:

:local ifaddr [/ip address get [find interface=dsl-line]]
:local ipv4addr ($ifaddr->"address")
:local newaddr [:pick $ipv4addr 0 [:find $ipv4addr "/"] ]

Any ideas why the foreach loop does not work? I would prefer that method, because it does not branch into the DDNS update code.

Greetings,
Wil
 
wil
just joined
Topic Author
Posts: 10
Joined: Wed Jun 04, 2014 4:42 pm

Re: getting IP of DSL interface

Sat Feb 25, 2017 10:55 pm

Apparently the snippet

:local ifaddr [/ip address get [find interface=dsl-line]]

also return sometimes the IP address of the 3G backup link instead of the DSL one. Could there be a race condition if the script is triggered by the via "on-up" in the ppp profile?
 
macns
just joined
Posts: 22
Joined: Mon Jul 21, 2014 12:36 pm

Re: getting IP of DSL interface

Sun Feb 26, 2017 1:04 am

Yes probably this is it. You could try inserting a delay of a few seconds before getting the address of the -just came up- ppp interface.

Not sure why you want to use the loop though or why are you not putting this script on a scheduler to run every few minutes. That is how I'm doing it along with an http "myip" service I have set up. Can't post code right now but if needed I will tomorrow.
 
wil
just joined
Topic Author
Posts: 10
Joined: Wed Jun 04, 2014 4:42 pm

Re: getting IP of DSL interface

Sun Feb 26, 2017 11:22 pm

Not sure why you want to use the loop though or why are you not putting this script on a scheduler to run every few minutes. That is how I'm doing it along with an http "myip" service I have set up. Can't post code right now but if needed I will tomorrow.
Hi macns,

I have a check to see if the IP address has changed, and only if it has I call the webapi to update the DNS record. Additionally to the "on-up" event the script is also run every 3 minutes by the scheduler. But still I am somehow stuck with the wrong DNS record once the issue happens. I got to check the environment variable that hold the last IP from the DNS update next time this occurs, but I think last time its value was the IP from the DSL interface. Maybe the /fetch call for up DNS updated failed somehow. But then I assign the environment variable for the last updated IP afterwards, which I think should be skipped if there some error while executing the script.

Greetings,
wil

Who is online

Users browsing this forum: durkonos and 25 guests