[Script] Dial PPPoE until a Certain IP Range is Obtained

Hi everyone, I have a script to share. It’s for those who wants a certain IP range when connecting with PPPoE to your ISP. Instead of sitting and rebooting the router or disabling and enabling the pppoe client, all you have to do is run this script.

You may want a certain IP range for any number of reasons. Sometimes I use this to check the routes that my ISP uses. The routes they use differs for certain IP ranges. Hope someone finds this useful.

Also in the Wiki

3 variables to set, if, targetip and pppoedelay.
if: name of your pppoe-client interface
targetip: eg: 177.0.0.0/8 or 65.50.0.0/16
pppoedelay: Enough delay so that your ISP gives a new IP instead of the previous one. You can play around with this.

:global if "pppoe-out1"
:global targetip 210.0.0.0/8
:global currentip [/ip address get [/ip address find interface=$if ] address]
:global ip $currentip
:global pppoedelay 10s

:put "Current IP: $currentip\r\nTarget: $targetip\r\n"

:while (!($currentip in $targetip)) do={
     put "$currentip is not in $targetip. Getting new IP. $pppoedelay delay"
     /interface disable $if
     :delay $pppoedelay
     /interface enable $if
     :do {delay 1s; put "waiting for pppoe-server"} while=( [/interface get unifi running]=false)
     :set currentip [/ip address get [/ip address find interface=$if ] address]
     :set currentip ([[:parse ":return $currentip"]])
     :set ip $currentip
     }
:put "Target obtained: $currentip"

Best to run from the CLI so you can see the output. Example:

[admin@RB2011UAS] /system script> run pppoe-ip-cidr 
Current IP: 175.144.175.247/32
Target: 210.0.0.0/8

175.144.175.247/32 is not in 210.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
175.144.175.247/32 is not in 210.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
175.136.3.130/32 is not in 210.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
175.136.3.130/32 is not in 210.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
118.101.248.194/32 is not in 210.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
175.144.175.247/32 is not in 210.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
118.100.151.60/32 is not in 210.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
waiting for pppoe-server
Target obtained: 210.187.203.102/32
[admin@RB2011UAS] /system script>

That’s useful in many situation :slight_smile:

Hi Syed, thanks and what a coincidence. Just 24hrs ago, I was at your website referring to “Mikrotik DUAL WAN Load Balancing using PCC method” while configuring load balancing for my house. Your article helped immensely.

The results from 2 x FTTH 30/10mbps WANs. (1 PPPoE and 1 wlan bridged to my neighbour’s Asus RT-N12)

Thank you very much for that.

Hello, I am using the following script, but I received an error response. What do I need to do?thank you.

:global if “pppoe-out1”
:global targetip 223.0.0.0/8
:global currentip [/ip address get [/ip address find interface=$if ] address]
:global ip $currentip
:global pppoedelay 10s

:put “Current IP: $currentip\r\nTarget: $targetip\r\n”

:while (!($currentip in $targetip)) do={
put “$currentip is not in $targetip. Getting new IP. $pppoedelay delay”
/interface disable $if
:delay $pppoedelay
/interface enable $if
:do {delay 1s; put “waiting for pppoe-server”} while=( [/interface get unifi running]=false)
:set currentip [/ip address get [/ip address find interface=$if ] address]
:set currentip ([[:parse “:return $currentip”]])
:set ip $currentip
}
:put “Target obtained: $currentip”
:while (!($currentip in $targetip)) do={
put “$currentip is not in $targetip. Getting new IP. $pppoedelay delay”
/interface disable $if
:delay $pppoedelay
/interface enable $if
:do {delay 1s; put “waiting for pppoe-server”} while=( [/interface get unifi running]=false)
:set currentip [/ip address get [/ip address find interface=$if ] address]
:set currentip ([[:parse “:return $currentip”]])
:set ip $currentip
}
:put “Target obtained: $currentip”

[admin@MikroTik] /system script> run check
Current IP: 100.70.236.16/32
Target: 223.0.0.0/8

100.70.236.16/32 is not in 223.0.0.0/8. Getting new IP. 00:00:10 delay
waiting for pppoe-server
no such item

how to make dial on specific 3 ip?
i want to dial to 3 ip, example ip 1.0.0.0/8 2.0.0.0/8 3.0.0.0/8?
thanks fo best scritp

I want to do it, too. But, how to allow all ip except 10.0.0.0/8 only?
Thanks for sharing

Please not use every variable as global
Please correct the [ code ] declaration at console example
Please set a [Script] in title to [HowTo] if this is not question but solved manual.

Other example is when we use LTE and our ISP give us the same IP and we must do reconnecting until we receive other IP to reset limitation on some video share portals. Or until we receive IP who is not in smtp blacklisting range.
This is opposite but you can do a TRUE/FALSE value to change it in script.

In how way you obtain a wiki privilege ?