Blacklisting in Asterisk

I will give an example of blocking incoming calls by phone number, or you can perform other actions for the phone numbers specified in the list.

Connect to Asterisk:

asterisk -rvv

View information about the BLACKLIST feature (very old versions of Asterisk may not have it):

core show function BLACKLIST

An example of adding a phone number to the black list (the number must be specified in the format in which it comes with an incoming call):

database put blacklist +380661234567 1

An example of viewing the contents of all lists and the blacklist:

database show
database show blacklist

An example of deleting a phone number from the specified list:

database del blacklist +380661234567

Let’s say you have a dial plan in /etc/asterisk/extensions.conf (I’ll give a very simple example):

[ixnfocom]
exten => s,1,DIAL(SIP/201,60)
exten => s,n,Hangup()

Now let’s add a check of the phone number in the blacklist to its beginning:

[ixnfocom]
exten => s,1,GotoIf($[${BLACKLIST()}=1]?blacklist)
exten => s,n,GoTo(ixnfocom,s,4)
exten => s,n(blacklist),Hangup()
exten => s,n,DIAL(SIP/201,60)
exten => s,n,Hangup()

The first line searches for a phone number in the list with value 1, if it finds it and its value is 1, then returns 1.
The second line translates to the 4th line all other phone numbers that are not in the list, that is, it makes a normal call as before.
The third line hangs up for numbers that are on the list.

See also my other articles about Asterisk.

Leave a comment

Leave a Reply

Discover more from IT Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading