Ok, if you use Asterisk (or a Do It Yourself type VoIP service), you sometimes do not receive the CNAM (think Caller ID with Name data) from your carrier. Well, since geeks like information and anything “free,” there’s a simple way to use the internet to do a reverse number lookup query. So, if you’re a technical type, keep reading… otherwise, non-geek posts will return very soon.

So, using a simple Perl script, you can check many resources and attempt to get the calling party’s name. There are tons of caller id lookup scripts out there, but most require the Asterisk Perl AGI module, a localized NPA/NXX database, or a local database query.

Since I don’t like installing the module, don’t want to install a local lookup table, and don’t wish to cache CID names in a database, I’ve modified publicly available scripts as follows (also, check up the write up on Team Forrest, with a little more detail):

Basically, what the script does is lookup the cidname from the CID number. I pass the script an argument (the caller id number) and it checks AnyWho, Google, and 411.com (in order). I chose 411 last and just use it to replace an NPA/NXX table. Basically, if AnyWho and Google fail, I’m assuming it’s a cell phone or unlisted number and will assume 411 will only return a location. If all fails, the script sets the callerid name to be the callerid number.

I’ve integrated it into asterisk by first creating a lookup context:

Basically, if the callerid name is present (and not the phonenumber), run the script. You can then call the script from anywhere in your Asterisk dialplan using a gosub routine. Such as:

Are there other ways to do this? Absolutely. And some even better 🙂 This way works for me… until I see a better way of doing it.