Mikrotik scripts
Debuging script Run in terminal inside "{ ... }"
Change IP-address of PPTP-server in PPTP-client settings
MikroTik RouterOS 6.40.3
# Name of PPTP connection on PPTP-client
:local pptpInterfaceID [/interface pptp-client find name="PPTP-CO"];
# Local IP
:local kievLocalIp 192.168.2.1
# External IP Addresses from IP in central office
:local pptpIp1 111.222.333.444
:local pptpIp2 222.333.444.555
# If local Ip is accessible - we will do nothing
:if ( [ping $kievLocalIp count=3] = 0) do={
# Check External IP-address
:if ( [ping $pptpIp1 count=3] != 0) do={
/log info "IP $pptpIp1 is accessible. Trying connect...";
/interface pptp-client set $pptpInterfaceID connect-to=$pptpIp1;
} else={
/log info "IP $pptpIp1 is not accessible"
:if ([ping $pptpIp2 count=3] != 0) do={
/log info "IP $pptpIp2 is accessible. Trying connect...";
/interface pptp-client set $pptpInterfaceID connect-to=$pptpIp2;
} else={
/log info "IP $pptpIp2 is not accessible";
/log warning "Cannot ping to any IP in Kiev";
}
}
}
Remove active SIP connections after some failover
# KILL ALL ACTIVE SIP CONNECTIONS
:foreach i in=[/ip firewall connection find dst-address~":5060"] do={
/log warning ("purge SIP connections: src:$[/ip firewall connection get $i src-address] dst:$[/ip firewall connection get $i dst-address]")
/ip firewall connection remove $i}
DHCP leases nitofications
:if ($leaseBound = "1") do={
:local ip $leaseActIP
:local mac $leaseActMAC
:local hostname "(unknown)"
:local isDynamic false
:foreach i in=[/ip dhcp-server lease find where mac-address=$mac and dynamic=yes] do={
:set isDynamic true
:local h [/ip dhcp-server lease get $i host-name]
:if ($h != "") do={ :set hostname $h }
}
:if ($isDynamic = true) do={
:local msg "New DHCP IP leased: $ip MAC: $mac Host: $hostname"
/tool fetch url="https://ntfy.domain.com/topic" http-method=post http-header-field="Authorization: Bearer tk_TOKEN" http-data=$msg
}
}