Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :global MainIf
- :global RsrvIf
- :global MainIfAddress
- :global RsrvIfAddress
- :local PingCount 3
- #Ping adresses for main gw
- :local PingTargetMain1 8.8.4.4
- :local PingTargetMain2 204.79.197.200
- #Ping adresses for reserve gw
- :local PingTargetReserve1 212.122.1.2
- :local PingTargetReserve2 209.132.183.181
- #Check main internet connection
- :local MainIfInetOk false;
- if ($MainIfAddress="") do={delay 5}
- if ($MainIfAddress!="") do={
- :local PingResult1 [/ping $PingTargetMain1 count=$PingCount interface=$MainIf]
- :local PingResult2 [/ping $PingTargetMain2 count=$PingCount interface=$MainIf]
- :set MainIfInetOk (($PingResult1 + $PingResult2) >= (2))
- :log info $MainIfInetOk
- }
- #Check reserved internet connection
- :local RsrvIfInetOk false;
- if ($RsrvIfAddress="") do={delay 5}
- if ($RsrvIfAddress!="") do={
- :local PingResult1 [/ping $PingTargetReserve1 count=$PingCount interface=$RsrvIf]
- :local PingResult2 [/ping $PingTargetReserve2 count=$PingCount interface=$RsrvIf]
- :set RsrvIfInetOk (($PingResult1 + $PingResult2) >= (2 ))
- }
- :put "MainIfInetOk=$MainIfInetOk"
- :put "RsrvIfInetOk=$RsrvIfInetOk"
- if (!$MainIfInetOk) do={
- /log warning "Main internet connection error"
- }
- if (!$RsrvIfInetOk) do={
- /log warning "Reserve internet connection error"
- }
- :local MainGWDistance [/ip route get [find comment="MainGW"] distance]
- :local RsrvGWDistance [/ip route get [find comment="RsrvGW"] distance]
- :put "MainGWDistance=$MainGWDistance"
- :put "RsrvGWDistance=$RsrvGWDistance"
- #SetUp gateways
- if ($MainIfInetOk && ($MainGWDistance >= $RsrvGWDistance)) do={
- /ip route set [find comment="MainGW"] distance=1
- /ip route set [find comment="RsrvGW"] distance=2
- /log error "Switch to main internet connection"
- delay 30
- /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"
- }
- if (!$MainIfInetOk && $RsrvIfInetOk && ($MainGWDistance <= $RsrvGWDistance)) do={
- /ip route set [find comment="MainGW"] distance=2
- /ip route set [find comment="RsrvGW"] distance=1
- /log error "Switch to reserve internet connection"
- delay 30
- /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"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement