Skip to content

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}