Page 1 of 1

script: check and reconnect pppoe-session.

Posted: Mon Apr 14, 2014 4:26 pm
by bingo220
Sometimes I have the situation when pppoe-session is connected, but hasn't an internet.
To fix it the pppoe must be reconnected.
Made a script for myself.
Maybe someone has the same problem.

script's steps:
1. Check pppoe-session status connected (if not connected - stop script)
2. Ping "8.8.8.8" five times (if ping is ok - stop script)
3. Ping "8.8.4.4" five times (if ping is ok - stop script)
4. Reconnect pppoe-session.


System-Scripts:
Name: check-inet
Policy: write,test,read
Source:
# Don't forget, if you've multiple ISPs
# HostPingA and HostPingB 
# must have the static routes.
# example:
# (if HostPingA=8.8.8.8; HostPingB=8.8.4.4;
# and GW of ISP1=172.16.18.1 ) 
# 
# /ip route 
# add dst-address=8.8.8.8 gateway=172.16.18.1 scope=10
# add dst-address=8.8.4.4 gateway=172.16.18.1 scope=10

##### Script Settings #####
:local WanName "pppoe-out1"
:local HostPingA "8.8.8.8"
:local HostPingB "8.8.4.4"
#####################

:local PingCount "5"
:local WanStat
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={ 
      :local pingresultB [/ping $HostPingB count=$PingCount]; 
      :if ($pingresultB = 0) do={ 
        :log error message="Script can not ping thru <$WanName>. Try to reconnect..."; 
        :interface pppoe-client disable $WanName; 
        :delay 5; 
        :interface pppoe-client enable $WanName; 
        :log warning message="PPPoE has Reconnected by script";
      }
    }
}
Then create shedule:
System-Sheduler:
Name: check-inet
Start Date: Jan/01/1970
Start Time: 00:00:00
Interval: 00:03:00
On Event: /system script run check-inet
Policy: write,test,read

Re: script: check and reconnect pppoe-session.

Posted: Mon Apr 14, 2014 5:51 pm
by rextended
Check locked PPPOE, PPTP, L2TP, SSTP, OVPN* PPP* connections (on Server side)
http://forum.mikrotik.com/viewtopic.php?f=9&t=83132

Hint: when you can, use simplicity and not use external service (8.8.8.8 for example) for check if YOUR network are working...

What's happen if google change dns ip address or shut down the service for maintenance?
Think about that...
Some users use google dns also for check routes against multiple providers.....

Adapted version of my script for multiple pppoe-client check:
:log info message="*** start the check off all pppoe-client connection ***";
:local pppTest value=[/interface pppoe-client find where running=yes];
:local pingNumber value=2;
:local pingMin value=1;
:local toAddress value="";
:foreach userTest in=$pppTest do={
 /interface pppoe-client monitor $userTest once do={ :set toAddress value=$"remote-address" };
 :local pingOk value=[:ping $toAddress count=$pingNumber];
 :if ($pingOk < $pingMin) do={
  :log warning message=([/interface pppoe-client get $userTest value-name=name]." unlocked: ".$pingOk." ping ok over ".$pingNumber." to ".$toAddress);
  /interface pppoe-client disable $userTest;
  /delay delay-time=5;
  /interface pppoe-client enable $userTest;
 }
};
:log info message="*** stop the check of all pppoe-client connection ***";

Re: script: check and reconnect pppoe-session.

Posted: Tue Dec 16, 2014 4:24 pm
by tpfresh
thank you bingo220 i has a same you problem it show "connect" but not internet
i have 3 pppoe-client(same ISP)+PCC Loadbalance. i not understan your script header
please describe me or give me full script script
# Don't forget, if you've multiple ISPs
# HostPingA and HostPingB
# must have the static routes.
# example:
# (if HostPingA=8.8.8.8; HostPingB=8.8.4.4;
# and GW of ISP1=172.16.18.1 )
#
# /ip route
# add dst-address=8.8.8.8 gateway=172.16.18.1 scope=10
# add dst-address=8.8.4.4 gateway=172.16.18.1 scope=10
this ip>route List me I must to add anything to ?

Image


Thank you

Re: script: check and reconnect pppoe-session.

Posted: Tue Dec 16, 2014 9:46 pm
by bingo220
tpfresh, I use the same script. It's already corrected for you. Three steps...

At first, add the routes:
/ip route
add dst-address=213.180.193.58 gateway=49.48.216.1 scope=10 comment="Static PING way by ISP1-host1"
add dst-address=198.41.213.157 gateway=49.48.216.1 scope=10 comment="Static PING way by ISP1-host2"
add dst-address=92.222.9.20 gateway=49.48.216.1 scope=10 comment="Static PING way by ISP1-host3"
add dst-address=66.220.12.174 gateway=171.4.112.1 scope=10 comment="Static PING way by ISP2-host1"
add dst-address=91.226.30.5 gateway=171.4.112.1 scope=10 comment="Static PING way by ISP2-host2"
add dst-address=91.121.64.153 gateway=171.4.112.1 scope=10 comment="Static PING way by ISP2-host3"
add dst-address=193.105.77.2 gateway=223.206.184.1 scope=10 comment="Static PING way by ISP3-host1"
add dst-address=85.159.233.18 gateway=223.206.184.1 scope=10 comment="Static PING way by ISP3-host2"
add dst-address=92.243.3.119 gateway=223.206.184.1 scope=10 comment="Static PING way by ISP3-host3"
Second step - create the script:
System-Scripts:
Name: check-inet
Policy: write,test,read
Source:
##### Script Settings #####
:local WanName "pppoe-out1"
:local HostPingA "213.180.193.58"
:local HostPingB "198.41.213.157"
:local HostPingC "92.222.9.20"
#####################

:local PingCount "3"
:local WanStat
### TEST-1 ###
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
### TEST-2 ###
:delay 15;
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
### TEST-3 ###
:delay 15;
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
### TEST-4 LAST ###
:delay 15;
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
        :log error message="Script (check-inet) can not ping thru <$WanName>. Try to reconnect...";
        :interface pppoe-client disable $WanName;
        :delay 5;
        :interface pppoe-client enable $WanName;
        :log warning message="PPPoE <$WanName> has Reconnected by script (check-inet)";

}}}}}}}}}}}}}}}}

######## SCRIPT FOR WAN-2 #########

##### Script Settings #####
:local Wan2Name "pppoe-out2"
:local Host2PingA "66.220.12.174"
:local Host2PingB "91.226.30.5"
:local Host2PingC "91.121.64.153"
#####################

:local Ping2Count "3"
:local Wan2Stat
### TEST-1 ###
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
### TEST-2 ###
:delay 15;
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
### TEST-3 ###
:delay 15;
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
### TEST-4 LAST ###
:delay 15;
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
        :log error message="Script (check-inet) can not ping thru <$Wan2Name>. Try to reconnect...";
        :interface pppoe-client disable $Wan2Name;
        :delay 5;
        :interface pppoe-client enable $Wan2Name;
        :log warning message="PPPoE <$Wan2Name> has Reconnected by script (check-inet)";

}}}}}}}}}}}}}}}}

######## SCRIPT FOR WAN-3 #########

##### Script Settings #####
:local Wan3Name "pppoe-out3"
:local Host3PingA "193.105.77.2"
:local Host3PingB "85.159.233.18"
:local Host3PingC "92.243.3.119"
#####################

:local Ping3Count "3"
:local Wan3Stat
### TEST-1 ###
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
### TEST-2 ###
:delay 15;
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
### TEST-3 ###
:delay 15;
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
### TEST-4 LAST ###
:delay 15;
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
        :log error message="Script (check-inet) can not ping thru <$Wan3Name>. Try to reconnect...";
        :interface pppoe-client disable $Wan3Name;
        :delay 5;
        :interface pppoe-client enable $Wan3Name;
        :log warning message="PPPoE <$Wan3Name> has Reconnected by script (check-inet)";

}}}}}}}}}}}}}}}}

Third step - create shedule:
System-Sheduler:
Name: check-inet
Start Date: Jan/01/1970
Start Time: 00:00:30
Interval: 00:10:00
On Event: /system script run check-inet
Policy: write,test,read

Re: script: check and reconnect pppoe-session.

Posted: Wed Dec 17, 2014 4:36 am
by tpfresh
thank you bingo220 it work for me!

i have this problem a long time(1year) i try to find key word "ISP Failover" and other but it not work for me

this is script by me. It ok, but its has error.
you do not funny :lol: :lol: :lol:
:delay 10
:if ([/ping 110.164.252.223 interface=pppoe-out1 count=3] =0) do={
:log error "pppoe-out1 linkdown!"
:delay 5
/interface pppoe-client enable pppoe-out1
#command enable it will disable & enable auto
}
:if ([/ping 110.164.252.223 interface=pppoe-out2 count=3] =0) do={
:log error "pppoe-out2 linkdown!"
:delay 5
/interface pppoe-client enable pppoe-out2
}
:if ([/ping 110.164.252.223 interface=pppoe-out3 count=3] =0) do={
:log error "pppoe-out3 linkdown!"
:delay 5
/interface pppoe-client enable pppoe-out3
}
thank you a again

sorry i fair english lang

Re: script: check and reconnect pppoe-session.

Posted: Sun Feb 05, 2017 6:27 pm
by zivtal
tpfresh, I use the same script. It's already corrected for you. Three steps...

At first, add the routes:
/ip route
add dst-address=213.180.193.58 gateway=49.48.216.1 scope=10 comment="Static PING way by ISP1-host1"
add dst-address=198.41.213.157 gateway=49.48.216.1 scope=10 comment="Static PING way by ISP1-host2"
add dst-address=92.222.9.20 gateway=49.48.216.1 scope=10 comment="Static PING way by ISP1-host3"
add dst-address=66.220.12.174 gateway=171.4.112.1 scope=10 comment="Static PING way by ISP2-host1"
add dst-address=91.226.30.5 gateway=171.4.112.1 scope=10 comment="Static PING way by ISP2-host2"
add dst-address=91.121.64.153 gateway=171.4.112.1 scope=10 comment="Static PING way by ISP2-host3"
add dst-address=193.105.77.2 gateway=223.206.184.1 scope=10 comment="Static PING way by ISP3-host1"
add dst-address=85.159.233.18 gateway=223.206.184.1 scope=10 comment="Static PING way by ISP3-host2"
add dst-address=92.243.3.119 gateway=223.206.184.1 scope=10 comment="Static PING way by ISP3-host3"
Second step - create the script:
System-Scripts:
Name: check-inet
Policy: write,test,read
Source:
##### Script Settings #####
:local WanName "pppoe-out1"
:local HostPingA "213.180.193.58"
:local HostPingB "198.41.213.157"
:local HostPingC "92.222.9.20"
#####################

:local PingCount "3"
:local WanStat
### TEST-1 ###
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
### TEST-2 ###
:delay 15;
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
### TEST-3 ###
:delay 15;
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
### TEST-4 LAST ###
:delay 15;
/interface pppoe-client monitor $WanName once do={ :set WanStat $status}
:if ($WanStat = "connected") do={
  :local pingresultA [/ping $HostPingA count=$PingCount];
    :if ($pingresultA = 0) do={
      :local pingresultB [/ping $HostPingB count=$PingCount];
      :if ($pingresultB = 0) do={
        :local pingresultC [/ping $HostPingC count=$PingCount];
        :if ($pingresultC = 0) do={
        :log error message="Script (check-inet) can not ping thru <$WanName>. Try to reconnect...";
        :interface pppoe-client disable $WanName;
        :delay 5;
        :interface pppoe-client enable $WanName;
        :log warning message="PPPoE <$WanName> has Reconnected by script (check-inet)";

}}}}}}}}}}}}}}}}

######## SCRIPT FOR WAN-2 #########

##### Script Settings #####
:local Wan2Name "pppoe-out2"
:local Host2PingA "66.220.12.174"
:local Host2PingB "91.226.30.5"
:local Host2PingC "91.121.64.153"
#####################

:local Ping2Count "3"
:local Wan2Stat
### TEST-1 ###
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
### TEST-2 ###
:delay 15;
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
### TEST-3 ###
:delay 15;
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
### TEST-4 LAST ###
:delay 15;
/interface pppoe-client monitor $Wan2Name once do={ :set Wan2Stat $status}
:if ($Wan2Stat = "connected") do={
  :local ping2resultA [/ping $Host2PingA count=$Ping2Count];
    :if ($ping2resultA = 0) do={
      :local ping2resultB [/ping $Host2PingB count=$Ping2Count];
      :if ($ping2resultB = 0) do={
        :local ping2resultC [/ping $Host2PingC count=$Ping2Count];
        :if ($ping2resultC = 0) do={
        :log error message="Script (check-inet) can not ping thru <$Wan2Name>. Try to reconnect...";
        :interface pppoe-client disable $Wan2Name;
        :delay 5;
        :interface pppoe-client enable $Wan2Name;
        :log warning message="PPPoE <$Wan2Name> has Reconnected by script (check-inet)";

}}}}}}}}}}}}}}}}

######## SCRIPT FOR WAN-3 #########

##### Script Settings #####
:local Wan3Name "pppoe-out3"
:local Host3PingA "193.105.77.2"
:local Host3PingB "85.159.233.18"
:local Host3PingC "92.243.3.119"
#####################

:local Ping3Count "3"
:local Wan3Stat
### TEST-1 ###
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
### TEST-2 ###
:delay 15;
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
### TEST-3 ###
:delay 15;
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
### TEST-4 LAST ###
:delay 15;
/interface pppoe-client monitor $Wan3Name once do={ :set Wan3Stat $status}
:if ($Wan3Stat = "connected") do={
  :local ping3resultA [/ping $Host3PingA count=$Ping3Count];
    :if ($ping3resultA = 0) do={
      :local ping3resultB [/ping $Host3PingB count=$Ping3Count];
      :if ($ping3resultB = 0) do={
        :local ping3resultC [/ping $Host3PingC count=$Ping3Count];
        :if ($ping3resultC = 0) do={
        :log error message="Script (check-inet) can not ping thru <$Wan3Name>. Try to reconnect...";
        :interface pppoe-client disable $Wan3Name;
        :delay 5;
        :interface pppoe-client enable $Wan3Name;
        :log warning message="PPPoE <$Wan3Name> has Reconnected by script (check-inet)";

}}}}}}}}}}}}}}}}

Third step - create shedule:
System-Sheduler:
Name: check-inet
Start Date: Jan/01/1970
Start Time: 00:00:30
Interval: 00:10:00
On Event: /system script run check-inet
Policy: write,test,read
The ping is via specific pppoe-client ? or if I have internet access I will get ping at all pppoe-clients even that one or more is disconnected ? (I mean that is check each client if a live or check if I have internet access) ?