Messinet Secure Services
wiki:LocalCallingAreaGrabber
Last modified 12 months ago Last modified on 06/04/12 05:50:29

Local Calling Area Grabber

This cron script creates and/or updates Asterisk extension matches for area codes and prefixes which are treated as "Local Calls" derived from either AT&T or the Local Calling Guide and should not incur local-toll or long-distance charges when called from the area code and prefix you designate.

If you are an AT&T subscriber, you will obtain more accurate results using the att-local-call.cron script instead of the localcallingguide-local-call.cron script.

Browse Source / Download / Git Clone

The Process

  • The cron script downloads the current area codes and prefixes from
  • After parsing the received data, the cron script creates a static file with extension matches.
  • The script also keeps a local file copy of the previous update and compares it with the current update. If there were no changes, It won't waste time or resources reloading Asterisk.

Asterisk Configuration

You will need to configure Asterisk to use the area code and prefix and extension matches generated by this cron script.

First, you need to configure your extensions.conf file. It is beneficial to use the DUNDi contexts for this purpose, even if you are not currently using DUNDi. That way, if you decide to employ DUNDi in the future, everything is already configured! Because I have a regular AT&T analog PSTN line, I need to block the outbound Caller*ID for those users who connect through DUNDi. With AT&T, I can block the outbound Caller*ID by dialing "*67" before dialing the number. The lastest version of the script uses the "Exec" application and the "IF" function to check if the call uses the accountcode "dundi" and if so, formats the dialstring with a "*67" included. See the section on DUNDi Integration below.

You use an #include statement to include the extension mapping file in your extensions.conf file.

[dundi-e164-via-pstn]
; Local access via PSTN
#include local-<area code>-<prefix>.conf

DUNDi Integration

If you plan to allow users to connect via DUNDi with this configuration, you will need to create or modify the [dundi] user in your iax.conf file, mapping incoming calls from the "dundi" user to the [dundi-e164-local]. In order for the Caller*ID blocking to take effect for your DUNDi peers, it is simplest to have "accountcode=dundi" in your "dundi" user in your iax.conf file as follows:

[dundi]
type=user
accountcode=dundi
context=dundi-e164-local
dbsecret=dundi/secret

You will also need to edit your dundi.conf file and configure the appropriate mappings as follows:

[mappings]
; "e164" DUNDi context mapping without CLID
e164 => dundi-e164-canonical,0,IAX2,dundi:${SECRET}@<YOUR_EXTERNAL_HOST_NAME>/${NUMBER}
e164 => dundi-e164-customers,100,IAX2,dundi:${SECRET}<YOUR_EXTERNAL_HOST_NAME>/${NUMBER}
e164 => dundi-e164-via-pstn,400,IAX2,dundi:${SECRET}<YOUR_EXTERNAL_HOST_NAME>/${NUMBER}

Script Customization

You need to edit the script to set the variables for your specific configuration.

####################
# DEFINE VARIABLES #
####################
# Define the URL from which to fetch the area code and prefix list. Visit
# http://www.localcallingguide.com/lca_prefix.php and enter your NPA and
# NXX; click submit; the resulting URL is what should be defined here.
URL='http://www.localcallingguide.com/lprefix.php?exch=047832'
#
# Define your 3-digit telephone area code and 3-digit telephone prefix.
AREACODE='773'
PREFIX='555'
#
# YOU MUST DEFINE A VALID E-MAIL ADDRESS TO WHICH THE RESULTING
# FILE CONTENTS WILL BE SENT FOR INSPECTION.
PBX_ADMIN_EMAIL='root@localhost'
#
# Enter the full /path/filename where you would like the output to be saved
# for use and comparison the next time the script is run.
OUTFILE="/etc/asterisk/local-$AREACODE-$PREFIX.conf"

Until you are comfortable with this script automatically reloading the extensions in Asterisk's dialplan, you should comment out the two lines near the bottom of the file that contain the following code:

/usr/sbin/asterisk -rx"dialplan reload"