Custom black/white list using external caller lookup / logic

I am setting up my home asterisk box to filter out spam calls and prevent them from ringing my home phones. I don’t like forcing everyone to use my IVR but I want to be able to force that for some calls.

I started with the freepbx dynamic routing module from:
but it was not dynamic enough. I also didn’t like having my complex sql statements in the asterisk etc files so I used this code as a base and made some concept changes.

Basically… when a call comes in, the dynamic route stuff does an http://localhost/check_callerid.php script call. That script does the heavy lifting. Currently it does something like:

  1. sql lookup to see if number/name is blacklisted, whitelisted or passes ( pass needs additional checks ) This also checks for ‘blocks’ of numbers… 81755512xx checks to see if the nubmer is in that block and acts accordingly.
  2. See if it matches an ‘allowed’ area code… my local are codes are 817, 214, 469, etc… so they get special processing. Non-local area codes go to the IVR.
  3. see if the name matches a pattern ( collection, newspaper, V0xxxx, etc and blacklists those.
  4. if it is a ‘pass’ I do an additional web page lookup to see if the number was reported to as a telemarketer and ivr them if they match that list.

the script returns whitelist, blacklist or screen and the dynamic route stuff finishes it off and handles the call accordingly.

I’ve only run this for a few days and had a few calls. I only get a few calls per day ( but I don’t like them interrupting my family so thats why I set this up. Just wanted to toss this out there and see if anyone had any thing good or bad to say about this.


This falls squarely within my current interests. I have been contemplating how best to approach doing something like this, perhaps with a standalone module, or perhaps with a hook into the call flow control module for non-timegroup conditional processing. Can you share the contents of the file ‘check_callerid.php’ somewhere on the 'net.

Please include a licensing note, and if you are making it freely available to anyone I suggest you release it under the GNU GPL/2 license.

I have uploaded my code to:

let me know if you have any questions or suggestions.