Community discussions

 
User avatar
soonwai
Member Candidate
Member Candidate
Topic Author
Posts: 162
Joined: Mon Feb 06, 2012 10:50 pm
Location: Kuala Lumpur

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

Mon Feb 27, 2017 10:22 am

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> 
Last edited by soonwai on Sat Mar 04, 2017 8:55 pm, edited 3 times in total.
 
User avatar
aacable
Member
Member
Posts: 423
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

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

Tue Feb 28, 2017 9:10 am

That's useful in many situation :)
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
User avatar
soonwai
Member Candidate
Member Candidate
Topic Author
Posts: 162
Joined: Mon Feb 06, 2012 10:50 pm
Location: Kuala Lumpur

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

Tue Feb 28, 2017 8:24 pm

That's useful in many situation :)
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)
Image

Thank you very much for that.
 
plhappy
just joined
Posts: 2
Joined: Mon Sep 03, 2018 12:16 pm

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

Sat Dec 29, 2018 6:21 am

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
 
iamspa
just joined
Posts: 1
Joined: Wed Oct 19, 2011 10:41 am

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

Fri Mar 01, 2019 11:07 am

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
 
ikbalyasid
just joined
Posts: 1
Joined: Thu Sep 12, 2019 8:45 am

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

Thu Sep 12, 2019 8:48 am

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
 
User avatar
SiB
Member Candidate
Member Candidate
Posts: 148
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

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

Thu Sep 12, 2019 2:25 pm

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 ?
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL | WebChat: Tokonda

Who is online

Users browsing this forum: No registered users and 6 guests