Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. # Set local variables
  2. :local firstInterface "ether2";
  3. :local secondInterface "Rostelekom";
  4. :local pingTo1 "8.8.8.8";
  5. :local pingTo2 "217.112.35.75";
  6. :local pingCount 5;
  7. :local stableConnectFrom 70;
  8. :local prefix ">>> ";
  9.  
  10. # Local variables
  11. :local firstInterfaceName $firstInterface;
  12. :local secondInterfaceName $secondInterface;
  13.  
  14. # Function to cleaning ARP table
  15. :local clearArp do={
  16. :local dumplist [/ip arp find]
  17. :foreach i in=$dumplist do={
  18. /ip arp remove $i
  19. }
  20. :log info ($prefix . "ARP cleaned");
  21. }
  22.  
  23. # Function to reconnect PPPoE connection
  24. :local reconnectPPPoE do={
  25. /interface pppoe-client set $nameInterface disable=yes;
  26. :delay 1s;
  27. /interface pppoe-client set $nameInterface disable=no;
  28. }
  29.  
  30. :log info ($prefix . "START PING to $pingTo1 & $pingTo2");
  31.  
  32. # Check FIRST interface
  33. /interface pppoe-client {
  34. :if ( [get $secondInterface disable] = true) do={
  35. set $secondInterface disable=no;
  36. :delay 5s;
  37. }
  38. }
  39.  
  40. # Check SECOND interface
  41. /interface ethernet {
  42. :if ( [get $firstInterface disable] = true) do={
  43. set $firstInterface disable=no;
  44. }
  45. }
  46.  
  47. /ip route {
  48. # Set objects to variables
  49. :set firstInterface [find dst-address="0.0.0.0/0" gateway=$firstInterfaceName];
  50. :set secondInterface [find dst-address="0.0.0.0/0" gateway=$secondInterfaceName];
  51.  
  52. # Check routes
  53. :if ( [get $firstInterface distance] != 2 ) do={
  54. set $firstInterface distance=2;
  55. :log info ($prefix . "Distance for " . $firstInterfaceName . " corrected");
  56. }
  57.  
  58. :if ( [get $secondInterface distance] != 1 && [get $secondInterface distance] != 3) do={
  59. set $secondInterface distance=3;
  60. :log info ($prefix . "Distance for " . $secondInterfaceName . " corrected");
  61. }
  62.  
  63. # Get ping successfully packets. In percent
  64. :local pingStatus \
  65. ((( [/ping $pingTo1 interface=$firstInterfaceName count=$pingCount] + \
  66. [/ping $pingTo2 interface=$firstInterfaceName count=$pingCount] ) / ($pingCount * 2)) * 100);
  67.  
  68. # Check Internet
  69. :if ( [get $firstInterface active] = false or $pingStatus < $stableConnectFrom) do={
  70.  
  71. :log info ($prefix . "FIRST NO INTERNET!!!");
  72.  
  73. # Change distance
  74. :if ( [get $secondInterface distance] != 1 ) do={
  75. set $secondInterface distance=1;
  76. :log info ($prefix . "Distance for " . $secondInterfaceName . " changed");
  77. $clearArp;
  78. }
  79.  
  80. $reconnectPPPoE nameInterface=$secondInterface;
  81.  
  82. } else={
  83. :log info ($prefix . "FIRST INTERNET CONNECTED");
  84.  
  85. # Change distance
  86. :if ( [get $secondInterface distance] != 3 ) do={
  87. set $secondInterface distance=3;
  88. :log info ($prefix . "Distance for " . $secondInterfaceName . " changed");
  89. $clearArp;
  90. }
  91. }
  92. }
  93.  
  94. :log info ($prefix . "END PING");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement