Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Script in IP DHCP Client

Wed Sep 28, 2022 4:06 pm

Cheers,
I have this script running in /system scheduler and it does it very well,

:if ([/ping 1.1.1.1 count=6] = 0) do={/ip dhcp-client release [find]}

My question is how do I put it in IP DHCP Client, I can't find how to do it.

IP DHCP CLIENT.jpg

Thanks for your help.




EL DONCITO
You do not have the required permissions to view the files attached to this post.
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: Script in IP DHCP Client

Wed Sep 28, 2022 10:00 pm

And what are your expectations? The script makes sense when run periodically from scheduler. But DHCP lease script is executed only on DHCP events (acquire address, lose address).
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Script in IP DHCP Client

Wed Sep 28, 2022 10:50 pm

I want it to do the same but set to IP DHCP Client





EL DONCITO.
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: Script in IP DHCP Client

Wed Sep 28, 2022 11:15 pm

And that should be better how exactly? Or how should it even work? If you run it from scheduler, it runs every X seconds/minutes/hours, whatever interval you used. If you add it to DHCP client, it will run once for each event. It won't be the same at all.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Script in IP DHCP Client

Wed Sep 28, 2022 11:30 pm

I would like it to be released when the IP that my isp delivers is down, do you understand me?

Can be done like this?



EL DONCITO.
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: Script in IP DHCP Client

Thu Sep 29, 2022 12:05 am

My guess is that it's not possible. If you need to check it repeatedly, then script running once is clearly not a best place for it. Unless it would accept endless loop, but it still wouldn't be good, because you'd need to synchronize it with other DHCP events that you don't control.

Back to beginning, what's wrong with scheduler when you say that it works well?
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Script in IP DHCP Client

Thu Sep 29, 2022 12:09 am

Just to know if it was possible anything else




EL DONCITO.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Script in IP DHCP Client

Sat Oct 01, 2022 12:53 pm

Would this be the endless loop?
:local stopRouterRun false
:do {
:delay 10s
} while=(!$stopRouterRun)

would there be something like this?
:local stopRouterRun false
:do {
/ip dhcp-client
:if ([/ping 1.1.1.1 count=6] = 0) do={/ip dhcp-client release [find]}
:delay 10s
} while=(!$stopRouterRun)


EL DONCITO.
 
gammy69er
Frequent Visitor
Frequent Visitor
Posts: 79
Joined: Sun May 18, 2014 3:01 am

Re: Script in IP DHCP Client

Wed Mar 22, 2023 6:56 am

Netwatch...
/tool netwatch add  host=1.1.1.1  timeout=15s down-script="/ip dhcp-client release numbers=0" comment="Monitor Cloudflare"
Obviously changing "numbers=0" for whatever interface this is on, and the timeout to what suits. You can also Log errors as you see fit. This is at a 1 second interval by default.

You can also write this to be added when you dhcp is bound - and then also remove when unbound (important). As to how - you'll have to research that for yourself (I recommend making one that suits - exporting and adding to dhcp-client script to simplify the process). Also you can do finds to get the variables you need - but I am deep in that hole ATM and have nothing to offer (apart from a search for comment is mostly doable).

V7 has more options for netwatch.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script in IP DHCP Client

Wed Mar 22, 2023 10:59 am

numbers=0
NO never use numbers.

You can also write this to be added when you dhcp is bound - and then also remove when unbound (important)
NO for same reason on previous posts


*********************************


If work do not change.

Endless loops are one idiocy, till exist the scheduler or netwatch.

Who is online

Users browsing this forum: No registered users and 19 guests