Mikrotik Dyndns update IP address

:global ddnsuser “dyndnsuser”
:global ddnspass “dyndnspass”
:global ddnshost “mycam.dvrdns.org”
:global theinterface strongvpn-germany

:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info (“DynDNS: No ip address on $theinterface .”)
} else={
:for i from=( [:len $ipfresh] – 1) to=0 do={
:if ( [:pick $ipfresh $i] = “/”) do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}

:if ($ipddns != $ipfresh) do={
:log info (“DynDNS: IP-DynDNS = $ipddns”)
:log info (“DynDNS: IP-Fresh = $ipfresh”)
:log info “DynDNS: Update IP needed, Sending UPDATE…!”
:global str “/nic/update\?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG”
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
password=$ddnspass dst-path=(“/DynDNS.”.$ddnshost)
:delay 1
:global str [/file find name=”DynDNS.$ddnshost”];
/file remove $str
:global ipddns $ipfresh
:log info “DynDNS: IP updated to $ipfresh!”
} else={
:log info “DynDNS: dont need changes”;
}
}

Mktik Failover Script

# ——————- header ——————-
# Script by Tomas Kirnak, version 1.0.7
# If you use this script, or edit and
# re-use it, please keep the header intact.
#
# For more information and details about
# this script please visit the wiki page at
# http://wiki.mikrotik.com/wiki/Failover_Scripting
# ——————- header ——————-

# ————- Modification ——————-
# Modified by Andrés López
# Failover using Firewall Mangle Rules
# ———————————————-

# Please fill the WAN interface names
:local canal_a ether1
:local canal_b ether2
:local canal_c ether3

# routing net marks
:local redadmin 0
:local redinvitados 1

# check gateways
:local PingTarget 8.8.8.8
:local FailTreshold 10

# Declare the global variables
:global PingFailCountISP1
:global PingFailCountISP2

# Status
:global canal_a_estado
:global canal_b_estado

# This inicializes the PingFailCount variables, in case this is the 1st time the script has ran
:if ([:typeof $PingFailCountISP1]=”nothing”) do={:set PingFailCountISP1 0}
:if ([:typeof $PingFailCountISP2]=”nothing”) do={:set PingFailCountISP2 0}

# This variable will be used to keep results of individual ping attempts
:local PingResult

# Check ISP1
:set PingResult [ping $PingTarget count=1 interface=$canal_a]
:put $PingResult

:if ($PingResult = 0) do={
:if ($PingFailCountISP1 < ($FailTreshold+2)) do={
:set PingFailCountISP1 ($PingFailCountISP1 + 1)

:if ($PingFailCountISP1 = $FailTreshold) do={
:log warning “Canal a is offline”
:set canal_a_estado 1
}
}
}

:if ($PingResult = 1) do={
:if ($PingFailCountISP1 > 0) do={
:set PingFailCountISP1 ($PingFailCountISP1-1)

:if ($PingFailCountISP1 = ($FailTreshold – 1)) do={
:log warning “Canal a is back”
:set canal_a_estado 0
}
}
}

# Check ISP2
:set PingResult [ping $PingTarget count=1 interface=$canal_b]
:put $PingResult

:if ($PingResult = 0) do={
:if ($PingFailCountISP2 < ($FailTreshold+2)) do={
:set PingFailCountISP2 ($PingFailCountISP2 + 1)

:if ($PingFailCountISP2 = $FailTreshold) do={
:log warning “Canal b is offline”
:set canal_b_estado 1
}
}
}

:if ($PingResult = 1) do={
:if ($PingFailCountISP2 > 0) do={
:set PingFailCountISP2 ($PingFailCountISP2-1)

:if ($PingFailCountISP2 = ($FailTreshold – 1)) do={
:log warning “Canal b is back”
:set canal_b_estado 0
}
}
}

# Indication flags
:put $canal_a_estado
:put $canal_b_estado

# Failover actions
:if ($canal_b_estado=1) do={
:log warning “Enviando redinvitados por canal c”
ip firewall mangle set new-routing-mark=canal_c $redinvitados
}

:if ($canal_a_estado=1) do={
:log warning “Enviando redadmin por canal c”
ip firewall mangle set new-routing-mark=canal_c $redadmin
}

:if ($canal_b_estado=0) do={
:log warning “Canal b estable”
ip firewall mangle set new-routing-mark=canal_b $redinvitados
}

:if ($canal_a_estado=0) do={
:log warning “Canal a estable”
ip firewall mangle set new-routing-mark=canal_a $redadmin
}

Mikrotik Dual Wan

ip firewall mangle add src-address=192.168.57.0/24 action=mark-routing new-routing-mark=net1 chain=prerouting

ip firewall mangle add src-address=192.168.56.2 action=mark-routing new-routing-mark=wan1 chain=output
ip route add gateway=192.168.56.1 routing-mark=wan1

ip firewall mangle add src-address=192.168.58.2 action=mark-routing new-routing-mark=wan2 chain=output
ip route add gateway=192.168.58.1 routing-mark=wan2

-----

NAT
ip firewall nat add chain=src-nat out-interface=ether1 action masquerade
ip firewall nat add chain=src-nat out-interface=ether2 action masquerade
ip firewall nat add chain=src-nat out-interface=ether3 action masquerade

MANGLE
ip firewall mangle add src-address=192.168.59.0/24 action=mark-routing new-routing-mark=admin chain=prerouting
ip firewall mangle add src-address=192.168.56.2 action=mark-routing new-routing-mark=canal_primario chain=output
ip route add gateway=192.168.56.1 routing-mark=canal_primario
ip firewall mangle add src-address=192.168.57.2 action=mark-routing new-routing-mark=canal_secundario chain=output
ip route add gateway=192.168.57.1 routing-mark=canal_secundario
ip firewall mangle add src-address=192.168.58.2 action=mark-routing new-routing-mark=canal_terciario chain=output
ip route add gateway=192.168.58.1 routing-mark=canal_terciario

ROUTE
ip route rule add dst-address=0.0.0.0/0 routing-mark=admin table=canal_primario action=lookup
ip route rule add dst-address=0.0.0.0/0 routing-mark=admin2 table=canal_secundario action=lookup
ip route rule add dst-address=0.0.0.0/0 routing-mark=admin3 table=canal_primario action=lookup

Maillog Enhanced Queries

POSTFIX

E-Mails TO specific address ignoring amavis delivered queue “relay=127.0.0.1”

cat postfix| grep -v Greylisting | grep -i "to=<foo@foo>" | grep -Ev 'relay=dfilt|relay=127.0.0.1' | awk '{print $6}' | grep -v NOQUEUE | sort | uniq | while read L; do echo -e "\n------$L------\n" && grep $L postfix; done > output.txt; COUNT=`cat postfix| grep -v Greylisting | grep -i "to=<foo@foo>" | grep -Ev 'relay=dfilt|relay=127.0.0.1' | awk '{print $6}' | grep -v NOQUEUE | sort | uniq | wc -l` && echo -e "\n\nTOTAL CORREOS = $COUNT\n" >> output.txt

E-Mails FROM specific address ignoring amavis delivered queue “relay=127.0.0.1”

cat postfix| grep -i "from=<foo@foo>" | awk '{print $6}' | grep -v NOQUEUE | sort | uniq > temp.queues ; cat temp.queues | while read L; do grep $L postfix| grep -E 'relay=127.0.0.1|relay=dfilt' | awk '{print $6}' ; done > temp.queues.2 ; diff temp.queues temp.queues.2 | grep "<" | awk '{print $2}' | while read Z; do echo -e "\n-----$Z-----\n" && grep $Z postfix; done > output.txt; COUNT=`diff temp.queues temp.queues.2 | grep "<" | wc -l` && echo -e "\n\nTOTAL CORREOS = $COUNT\n" >> output.txt; rm temp.queues* -rf

handy linux and technology info