N
N
Nikodim Vakhmetov2016-05-26 16:31:01
Mikrotik
Nikodim Vakhmetov, 2016-05-26 16:31:01

How to create a Mikrotik pppoe-client reconnect script based on parsing the first IP octet?

I know the question has already been raised. Based on this script, I fixed it to reconnect pppoe-client in order to get away from an IP address that is not accessible from the outside:

:delay 10
:local "currentIP" [:pick [/ip address get [find interface =pppoe-out1] address ] 0 2]
:while ($currentIP = 82) do={
/interface pppoe-client enable pppoe-out1
}

Please point out the error, the script stubbornly does not want to work .... I understand with my mind that it is not difficult to debug a 4-line script, but Mikrotik is located remotely and stubbornly tries to get an address from a subnet inaccessible from outside ....
After rereading the script, over which I suffered for 3 days (no need to laugh, it was late in the evenings... :) I realized that there is no "currentIP" check in the while - do loop. Most likely it would be more logically correct:
:delay 10
:local "currentIP" [:pick [/ip address get [find interface =pppoe-out1] address ] 0 2]
:while ($currentIP = 82) do={
/interface pppoe-client enable pppoe-out1
:delay 2
:local "currentIP" [:pick [/ip address get [find interface =pppoe-out1] address ] 0 2]
}

But somewhere nearby there should be a more elegant solution ...
How to implement a check of more than one octet in this form?
:while ($currentIP = 82 | 83)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Romanov, 2016-05-26
@atimspb

Read carefully the answer to the script that you took as a basis. There is a simple and very beautiful solution (not mine). Easily customizable to your needs:

:global newIP [/ip address get [find interface="PPPoE"] address];

:if (($newIP in 82.0.0.0/8)||($newIP in 83.0.0.0/8)) do={

/interface pppoe-client disable PPPoE
:delay 30
/interface pppoe-client enable PPPoE
}

It is now very convenient to write scripts in a PPP profile. Copy the profile specifically for this connection, implant it there and enjoy)
ZY . Sorry, there were inaccuracies. Check again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question