Reference Post:
Following is short script to reconnect PPPoE dialer if it receives any private IP from the ISP including 10.x.x.x / 172.x.x.x & 192.x.x.x series.
# Script to find if wan link have private ip and act accordingly, # Tested with Mikrotik ROS 5.x & 6.x versions # 19-APR-2016 / Syed Jahanzaib # Set your WAN Interface name , i have added pppoe-out1 , change it as required :local WANINTERFACE :set WANINTERFACE pppoe-out1 # Find Public IP from pppoe-out1 interface & cut subnet :local WANIP [/ip address get [find where interface=$WANINTERFACE] address]; :set WANIP [:pick $WANIP 0 ([:len $WANIP]-3) ]; # Match if IP address starts with private address 10.* :if ($WANIP ~"^[0-9 ]*10") do={ :log warning "Private ip address found !!!" # Set your action here , like Re-Connect the pppoe-link # /interface pppoe-client disable pppoe-out-1 # :delay 3 # /interface pppoe-client enable pppoe-out-1 } else={ # Match if IP address starts with private address 172.* :if ($WANIP ~"^[0-9 ]*172") do={ :log warning "Private ip address found !!!" # Set your action here , like Re-Connect the pppoe-link # /interface pppoe-client disable pppoe-out-1 # :delay 3 # /interface pppoe-client enable pppoe-out-1 } else={ # Match if IP address starts with private address 192.* :if ($WANIP ~"^[0-9 ]*192") do={ :log warning "Private ip address found !!!" # Set your action here , like Re-Connect the pppoe-link # /interface pppoe-client disable pppoe-out-1 # :delay 3 # /interface pppoe-client enable pppoe-out-1 } else={ # If above statement do not match, then consider it a public ip and take no action, just log : ~ ) :log warning "Public IP - $WANIP - Found, OK ! No action required" # OR Set your desire action here if required } } } # Script Ends Here ...
Reference: https://forum.mikrotik.com/viewtopic.php?t=107231
Regard’s
Syed Jahanzaib
wow it work great thanks
LikeLike
Comment by dioey — October 16, 2017 @ 3:44 PM
Good.
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — October 16, 2017 @ 3:47 PM
very helpful scripts and work great… thanks!
but i have another problem like this …. may i email you ?
LikeLike
Comment by itmdn — May 9, 2018 @ 7:34 AM
but i don’t know you email … maybe can u email me first ?
thx
LikeLike
Comment by itmdn — May 9, 2018 @ 7:35 AM
or i just ask here ….
i need help about scripts like up there …. but the different is not my mikrotik as pppoe client, but the modem as pppoe/the dialer.
i can’t change the modem setting because locked by ISP, so possible to help me make scripts that can check private ip ?
tq sir.
LikeLike
Comment by itmdn — May 9, 2018 @ 9:40 AM
I have same problem as itmdn : the modem/ont as the dialer.
I can access ont via telnet/ssh, but don’t know what next.
Can anyone help, pls?
LikeLike
Comment by Setinggil Sj — November 12, 2019 @ 12:16 PM
Works flawlessly. Thank you very much. Just one simple question. What if we need specific subnet of public IP address on PPPoE? Let’s say, we need to get 172.17.11.0 – 172.17.11.254.
LikeLike
Comment by ian — September 22, 2020 @ 8:54 AM