Welcome to It-Slav.Net blog
Peter Andersson

I've already got a female to worry about. Her name is the Enterprise.
-- Kirk, "The Corbomite Maneuver", stardate 1514.0

I have been noticing an increasing number of telemarketing phonecalls the last weeks and I would like to avoid having those callers disturbing me or my family. They have been calling at 9am, 11am, 1pm, 8pm during the weekdays, saturday and sunday.


I have been running an asterisk system to handle my VoIP calles the last years and I have been using it for a number of things during the time.

I also use firewalls to secure incoming and outgoing IP traffic in my home network, so I thought the asterisk system could be used to do handle a “blacklist” of telephone number on my PSTN.

I would also like the asterisk system to kick in before my normal telephone gets the call and starts ringing.

If it detects a telemarketing caller, I would like it to answer the call and give a prerecorded message saying something like “You are calling from a unauthorised source. Please do not call again, this telephone line is being monitored.” and then just drop the line.


I found a list of known Swedish CallerID numbers on the Internet that I can use to “jumpstart” my blacklist. I only needed to have a dialplan and to configure my Sipura SPA-3000 ATA device to send my PSTN calls to my asterisk system.

This is how I configured it:

I started with configuring my SPA-3000 box to pick up the CallerID from my PSTN company.

The important configuration parameters are on the PSTN Tab in the Sipura web gui.

Line Enable: yes

Proxy: <my asterisk server IP>

User ID: pstn

Password: pstn

PSTN-To-VoIP Gateway Enable: yes

PSTN Ring Thru Line 1: no

PSTN Caller Default DP: 1

Line 1 Signal Hook Flash to PSTN: Disabled

Dial Plan 1: S0<:1010@gw1>


The Sipura dialplan is (as usual) pretty complicated (and powerful) and this dialplan sends the call to extension “1010” at the “gw1” interface in the SPA box.

I created a new context for the incoming PSTN, called [blacklist].


I also needed to create a sip device configuration for the Sipura box, so that the call would enter the correct context in the dialplan:




host=dynamic ;the extension can register from a dynamic IP

context=pstn ;incoming calls to to this extension



disallow=all ;disallow all codecs

allow=ulaw ;allow only the ulaw codec

deny= ; block all registrations from other networks

permit= ;only allow registrations from my LAN

qualify=600 ;monitor the ping delay


If you are using another PSTN-To-VoIP gateway adapter, the box needs to be configured to send the incoming CallerID to the asterisk box before answering the call.


The list of telephone numbers I downloaded needed to be inserted into a database in the asterisk system. Because there is about 1600 telephone numbers in the list, I had a script to load it into the asterisk database from a unix shell.

The list can be updated in realtime by using the commands:


ast> database put blacklist <number> 1 (for blacklisting)

ast> database del blacklist <number> 0 (for removing blacklisting)


You can run these commands on the asterisk console from the shell using the form:

# asterisk -r “databse put blacklist <number> 1″


To check if the list is populated, you can use the command:


ast> database list


It will give you the list of blacklisted number.


To make the blacklist matching work, I neede to insert a few lines of code into my /etc/asterisk/extensions.conf file:



exten => 1010,1,GotoIf(${DB_EXISTS(blacklist/${CALLERID(num)})}?blacklisted,s,1);



exten => s,1,Answer

exten => s,n,Wait(2)

exten => s,n,Playback(ss-noservice)

exten => s,n,Wait(1)

exten => s,n,Hangup


So, if a call is detected in the SPA3K box, it is sent to the “1010” extension in the pstn context. The CallerID is compared to the blacklisted entries in the asterisk database.

If the CallerID number is found in the databse, the call is sent to the blacklist extension and the “s” extension kicks in and handles the call.


The call is of course logged in the CDR database so I can monitor the number of telemarketing callers by day and week. But that is a different story.


Now, my family is happy to not answering those stupid calls every day!



2 Responses to “Telemarketing blacklisting using Asterisk”

  1. jm Says:

    Don’t forget the SIT tones before the ss-noservice!

  2. Lanic Says:

    Simple and effective, i like it!

Leave a Reply

Book reviews
FreePBX 2.5
Powerful Telephony Solutions

Asterisk 1.6
Build a feature rich telephony system with Asterisk

Learning NAGIOS 3.0

Cacti 0.8 Network Monitoring,
Monitor your network with ease!