Auto ban and unban numbers

I want to know how I can block incoming / outgoing calls to / from a number that has been dialed / called from more than x times for 24 hours.

I want to prevent the calling the same number more than 5 times. If anyones dials a number for the sixth time asterisks should block the call.

Similarly if someone (telemarketer) calls in to the system more than 5 times from same number I want to block the call for a period of 24 hours.

Is this possible? How can I achieve the same?

Consider me as a Noob :frowning:

You should be able to do this with the Asterisk Database.

wiki.asterisk.org/wiki/display/ … unction_DB

You can query if a database entry exists with this function:

wiki.asterisk.org/wiki/display/ … _DB_EXISTS

This example is off the top of my head and isn’t heavily tested but you should get the idea

exten => _nxxxxxx,1,NoOP()
same => n,ExecIf($[${DB_EXISTS(blacklist/${EXTEN})} = 0]?Set(DB(blacklist/${EXTEN})=1))
same => n,GotoIf($[${DB(blacklist/${EXTEN})} < 5]?INC:FAIL)
same => n(INC),Set(DB(blacklist/${EXTEN})=${MATH(${DB(blacklist/${EXTEN})}+1)})
same => n(DIAL),NoOP()
same => n,Dial(SIP/TRUNK/${EXTEN})
same => n,Hangup()
same => n(FAIL),Playtones(congestion)
same => n,Congestion(8)
same => n,Hangup()

Then just do a dbdeltree on the blacklist tree every night at midnight so you start fresh.