Dial PPPoE until a Certain IP Range is Obtained

From MikroTik Wiki
Revision as of 20:49, 4 March 2017 by Arpee (talk | contribs) (Created page with "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 disab...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.

https://forum.mikrotik.com/viewtopic.php?f=9&t=118871&p=585865

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.

[code]: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"[/code]

Best to run from the CLI so you can see the output. Example: [code][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> [/code]