Community discussions

MikroTik App
 
felixmoldovan
just joined
Topic Author
Posts: 2
Joined: Thu Oct 17, 2019 10:17 am

Script execution in DHCP client fails

Fri Oct 18, 2019 4:50 pm

Hello

I am an enthusiastic recent owner of a CRS328-24P-4S+, running RouterOS v6.45.6. The router is configured pretty much like out of the box, WAN on ether1 (DHCP from service provider) and LAN on bridge on the rest of the ports.
Out of all the available options to update my domain name (Google domains) with my dynamic IP, the first to consider was the script execution within the DHCP client options, triggered by the acquisition of a new lease. My understanding is that this is one of the use cases this could be used for. Great!
///

However, things didn't work out as expected:
  • I can positively see that the script is triggered, but the http request does not reach the endpoint on the Google Domains API
  • Further step was to consume an endpoint on the local LAN which WORKED! (http://192.168.1.100:8080). I ran a simple webserver on a local machine
  • Assuming that the internet connection is not "ready" in the same milisecond that the lease is acquired, I put a delay of 30s with the same result
  • The internet endpoint is consumed "no problemo" if the script is run manually or from the cli. It's only in the context of the lease acquisition where this happens
My conclusions so far:
  • The script is triggered and runs
  • An internet endpoint (via the same ether1 interface) is not consumed, only a local one (if triggered by the DHCP lease bonding)

Scripts in question are here:

// Script in DHCP client configuration
:if ($"bound" = "1") do {/system script run DDNS}


//Script in System->Script->DDNS, simply triggered this way in order to observe the execution counter tally 
/tool fetch url="https://dnstest.free.beeceptor.com/" mode=https
Thanks for the patience with the long story. Tried to provide as much meaningful information as possible.

And now my request for help
  • Any chance any of you manages to pass an internet http request from within this script?
  • Any suggestion on how to closer debug the script and catch the reason for the failed http request?

Appreciated. Felix
Last edited by felixmoldovan on Sat Oct 19, 2019 8:30 pm, edited 1 time in total.
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Script execution in DHCP client fails

Fri Oct 18, 2019 7:04 pm

I am no scripting / coding expert, but to me it looks like there are some fundamental errors in your script

Should the $"bound" include the "s?
The above is referring to a variable, bot don't see where it is initialized
Then as far as I know, the "do {" should be "do={"
 
felixmoldovan
just joined
Topic Author
Posts: 2
Joined: Thu Oct 17, 2019 10:17 am

Re: Script execution in DHCP client fails

Fri Oct 18, 2019 7:48 pm

Thanks. Note taken on your remarks... $ with "" works and it doesn't without the quotes. Perhaps something specific to local scope variables?
Applies also to $"lease-address" for example.

Also, you're right on the do={ but still, the script executes so I take it as the grace of the built in syntax assumption helper.

For what I can conclude, the trouble is (essentially) not within the script construction but some good reason why the http request fails to reach an internet URL while it can do it with a local one.

// To completely exclude the poor script syntax I confirm that same behaviour happens when simply adding the below in the DHCP client script box. True, in this case triggered once on the lease unbinding (no internet) and once on the re-bind (as described above)
/tool fetch url="http://dnstest.free.beeceptor.com/"
Thanks again

Who is online

Users browsing this forum: Bing [Bot] and 61 guests