Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. :global MainIf
  2. :global RsrvIf
  3. :global MainIfAddress
  4. :global RsrvIfAddress
  5.  
  6. :local PingCount 3
  7.  
  8. #Ping adresses for main gw
  9. :local PingTargetMain1 8.8.4.4
  10. :local PingTargetMain2 204.79.197.200
  11.  
  12. #Ping adresses for reserve gw
  13. :local PingTargetReserve1 212.122.1.2
  14. :local PingTargetReserve2 209.132.183.181
  15.  
  16. #Check main internet connection
  17. :local MainIfInetOk false;
  18.  
  19. if ($MainIfAddress="") do={delay 5}
  20.  
  21. if ($MainIfAddress!="") do={
  22. :local PingResult1 [/ping $PingTargetMain1 count=$PingCount interface=$MainIf]
  23. :local PingResult2 [/ping $PingTargetMain2 count=$PingCount interface=$MainIf]
  24.  
  25. :set MainIfInetOk (($PingResult1 + $PingResult2) >= (2))
  26. :log info $MainIfInetOk
  27. }
  28.  
  29. #Check reserved internet connection
  30. :local RsrvIfInetOk false;
  31.  
  32. if ($RsrvIfAddress="") do={delay 5}
  33.  
  34. if ($RsrvIfAddress!="") do={
  35. :local PingResult1 [/ping $PingTargetReserve1 count=$PingCount interface=$RsrvIf]
  36. :local PingResult2 [/ping $PingTargetReserve2 count=$PingCount interface=$RsrvIf]
  37.  
  38. :set RsrvIfInetOk (($PingResult1 + $PingResult2) >= (2 ))
  39. }
  40.  
  41. :put "MainIfInetOk=$MainIfInetOk"
  42. :put "RsrvIfInetOk=$RsrvIfInetOk"
  43.  
  44. if (!$MainIfInetOk) do={
  45. /log warning "Main internet connection error"
  46. }
  47.  
  48. if (!$RsrvIfInetOk) do={
  49. /log warning "Reserve internet connection error"
  50. }
  51.  
  52. :local MainGWDistance [/ip route get [find comment="MainGW"] distance]
  53. :local RsrvGWDistance [/ip route get [find comment="RsrvGW"] distance]
  54. :put "MainGWDistance=$MainGWDistance"
  55. :put "RsrvGWDistance=$RsrvGWDistance"
  56.  
  57.  
  58. #SetUp gateways
  59. if ($MainIfInetOk && ($MainGWDistance >= $RsrvGWDistance)) do={
  60. /ip route set [find comment="MainGW"] distance=1
  61. /ip route set [find comment="RsrvGW"] distance=2
  62. /log error "Switch to main internet connection"
  63. delay 30
  64. /tool e-mail send server=176.57.223.21 port=25 user=net.admin@xut.tw1.ru password=sd75755500 subject="Vl-opt router was switched to Podryad" to=itsmvvo@gmail.com body="Vl-opt router was switched to Podryad"
  65. }
  66.  
  67. if (!$MainIfInetOk && $RsrvIfInetOk && ($MainGWDistance <= $RsrvGWDistance)) do={
  68. /ip route set [find comment="MainGW"] distance=2
  69. /ip route set [find comment="RsrvGW"] distance=1
  70. /log error "Switch to reserve internet connection"
  71. delay 30
  72. /tool e-mail send server=176.57.223.21 port=25 user=net.admin@xut.tw1.ru password=sd75755500 subject="Vl-opt router was switched to Rostelekom" to=itsmvvo@gmail.com body="Vl-opt router was switched to Rostelekom"
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement