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.

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:

[pstn]

type=friend

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

context=pstn ;incoming calls to to this extension

secret=pstn

dtmfmode=rfc2833

disallow=all ;disallow all codecs

allow=ulaw ;allow only the ulaw codec

deny=0.0.0.0/0.0.0.0 ; block all registrations from other networks

permit=10.0.0.0/255.255.255.0 ;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: