#!/bin/sh echo "Table 56 contents IP:" echo "=====================" /sbin/ipfw table 56 list echo /sbin/ipfw table 56 list > /rul/_table56.change echo "=====================" #echo /sbin/ipfw table 56 flush > /rul/_table56.change #echo "Table 56 flushed" /usr/bin/grep -E ' chan_sip.c: Registration from .* No matching peer found' /var/log/asterisk/full | \ awk -F "'" '{ cmd=sprintf("echo /sbin/ipfw table 56 add "$4" 5060 >/dev/null 2>&1 >> /rul/_table56.change"); system(cmd); printf ("asterisk: Wrong peers: IP "$4" blocked\n"); }' /usr/bin/grep -E ' chan_sip.c: Registration from .* - ACL error' /var/log/asterisk/full | \ awk -F "'" '{ ips[$4]++ } END { for (a in ips){ if (ips[a]> 10 ){ cmd=sprintf("echo /sbin/ipfw table 56 add %s/32 5060 >/dev/null 2>&1 >> /rul/_table56.change",a); system(cmd); printf ("asterisk: Wrong ACL repeated [%d] times: IP [%s] blocked\n",ips[a],a); } } }' /usr/bin/grep -E ' chan_sip.c: Registration from .* Peer is not supposed to register$' /var/log/asterisk/full | \ awk -F "'" '{ ips[$4]++ } END { for (a in ips){ if (ips[a]> 10 ){ cmd=sprintf("echo /sbin/ipfw table 56 add %s/32 5060 >/dev/null 2>&1 >> /rul/_table56.change",a); system(cmd); printf ("asterisk: Wrong supposes repeated [%d] times: IP [%s] blocked\n",ips[a],a); } } }' /usr/bin/grep -E ' chan_sip.c: Registration from .* Wrong password$' /var/log/asterisk/full | \ awk -F "'" '{ ips[$4]++ } END { for (a in ips){ if (ips[a]> 20 ){ cmd=sprintf("echo /sbin/ipfw table 56 add %s/32 5061 >/dev/null 2>&1 >> /rul/_table56.change",a); system(cmd); printf ("asterisk: Wrong passwords repeated [%d] times: IP [%s] blocked\n",ips[a],a); } } }' chmod 744 /rul/_table56.change /rul/_table56.change >/dev/null 2>&1