Community discussions

MikroTik App
 
kalto
just joined
Topic Author
Posts: 18
Joined: Wed Jan 09, 2013 3:29 am

/ip address get not working anymore?

Sat Jan 25, 2014 11:58 am

Hi,

Updated to 6.7 recently. Not sure if this is the cause of my problem but it seems to match about the time this problem started.

I'm using a scheduler to check if my external IP address has changed and if it has changed, update my dyndns. Here is the scheduler script (run every 30 seconds):
:global currentIP;

:local newIP [/ip address get [find interface="pppoe-bell1"] address];

:if ($newIP != $currentIP) \
  do={ \
    :log info "ip address $currentIP changed to $newIP"; \
    /system script run ddns-update; \
    :set currentIP $newIP; \
  }
And here is the script:
/tool fetch url="http://freedns.afraid.org/dynamic/update.php?some_update_key==" mode=http dst-path=ExternalIP.txt
This has always worked flawlessly but recently, I realized that my dyndns wasn't being updated. In the log i'm getting only "ip address changed to 1.2.3.4/32" every 30 seconds (the frequency of the scheduler). Actually, it should say "ip address 4.3.2.1/32 changed to 1.2.3.4/32". Also, the global variable currentIP was staying empty.

After doing some testing, I discovered that the command /ip address get [find interface="pppoe-bell1"] address is returning nothing instead of the ip address of the interface. I tried all my interface, same thing. Tried /ip address get 0 address, nothing.

Anyone else having this behavior since upgrading to 6.7?
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: /ip address get not working anymore?

Mon Jan 27, 2014 8:09 pm

Hm... your script seems to work fine for me in 6.7, however I'm not testing the afraid.org part. If that part is failing for some reason, the code below it (which updates the global currentIP var) might not run. I would comment out the # /system script... line and try again just to see if the global var updates.
After doing some testing, I discovered that the command /ip address get [find interface="pppoe-bell1"] address is returning nothing instead of the ip address of the interface. I tried all my interface, same thing. Tried /ip address get 0 address, nothing.
Where are you testing this command that is returning nothing? In the terminal it will return nothing... unless you do something like:

ros code

:put [/ip address get [find interface="pppoe-bell1"] address]
You may have already tried this, but I would start by enclosing your entire script in brackets, put in a few :put statements, and then paste into the terminal. See if there are any errors or :put commands that aren't returning anything. Change/delete the currentIP global variable, run the script again, etc.

ros code

{
:global currentIP;
:put "currentIP: $currentIP"

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

:if ($newIP != $currentIP) \
  do={ \
    :log info "ip address $currentIP changed to $newIP"; \
    /system script run ddns-update; \
    :set currentIP $newIP; \
    :put "new currentIP: $currentIP"
}
}
 
kalto
just joined
Topic Author
Posts: 18
Joined: Wed Jan 09, 2013 3:29 am

Re: /ip address get not working anymore?

Tue Jan 28, 2014 4:16 pm

Thanks for the tips!

I'm still having trouble though.

So, here is what I did:

I first deleted the global variable currentIP to make sure that the script would run. Then, in a terminal, I ran this:
[adminROUTER] > [
[... :global currentIP;
[... :put $currentIP;
[... :local newIP [/ip address get [find interface="pppoe-bell1"] address];
[... :put $newIP
[... :if ($newIP != $currentIP) \
[\...   do={ \
[{\...     :put "ip address $currentIP changed to $newIP"; \
[{\...     :put "Running script"; \
[{\...     :set currentIP $newIP; \
[{\...   }
[... ]

1.2.3.4/32
ip address  changed to 1.2.3.4/32
Running script
So, everything is fine, the first line is empty because the variable doesn't exist yet. After that:
[admin@ROUTER] > /environment print
currentIP="1.2.3.4/32"
Again, everything's good. Let's run it again with the variable present:
[admin@ROUTER] > [
[... :global currentIP;
[... :put $currentIP;
[... :local newIP [/ip address get [find interface="pppoe-bell1"] address];
[... :put $newIP
[... :if ($newIP != $currentIP) \
[\...   do={ \
[{\...     :put "ip address $currentIP changed to $newIP"; \
[{\...     :put "Running script"; \
[{\...     :set currentIP $newIP; \
[{\...   }
[... ]
1.2.3.4/32
1.2.3.4/32
So, basically, everything works in terminal. I deleted the currentIP variable and re-enabled the scheduler to see if it worked, and again, I was getting those log message "ip address changed to 1.2.3.4/32" everytime the scheduler ran.

I deleted the variable again and changed my script to this to try to determine where the problem is:
:global currentIP;
:log info "$currentIP";
:local newIP [/ip address get [find interface="pppoe-bell1"] address];
:log info "$newIP";
:if ($newIP != $currentIP) \
  do={ \
    :log info "ip address $currentIP changed to $newIP"; \
    /system script run ddns-update; \
    :set currentIP $newIP; \
  }
The result is three lines (and repeating) in my logs:

First line with nothing, this is where the currentIP should be. It is ok to be empty on first run after deleting the variable.
Second line: 1.2.3.4/32
Third line: ip address changed to 1.2.3.4/32

So, there is a probleme somewhere with my global variable. Looks like the scheduler can't update my globel variable currentIP.



Ok, so, while I was writing this long post, I discovered that at some point, the script actually managed to update the currentIP variable, after like 10 tries. So, I reduced the timer and tried again. Same result, but after like 15 tries it managed to update the variable. This is getting weird. So, to stop flooding afraid.org with ddns update, I removed the /system script line just to get the log message. And now, it works flawlessly (execpt for the fact that my ddns doesn't get updated)! So, I'm guessing that there is something wrong with my ddns-update script that make the scheduler do weird things. Like the script fail and return something that the scheduler can't digest. I'll try to get it to log something to see what happens. I'll get back to you when I got some result!

Thank you!