[Asterisk-Users] Complete NPA-NXX list for USA/Canada npanxx,

Joe Greco jgreco at ns.sol.net
Mon Sep 19 06:47:06 MST 2005


> ----- Original Message ----- 
> > Since we are all trading secrets, check this site out
> >
> > http://members.dandy.net/~czg/lca_index.php
> >
> 
> You can get this Perl scripts that extract NPA-NXX directly from 
> dandy.net...
> 
> http://www.voip-info.org/tiki-index.php?page=ScopServ%20LCA%20Map

On a related note, I wanted our phones to display "city, st" for the
caller-ID name in the event that none was provided.

% cat jg-npanxx-loader.sh
#! /bin/sh -
#
# NPA-NXX data is at http://www.nanpa.com/reports/reports_cocodes_assign.html
# specifically http://www.nanpa.com/nanp1/allutlzd.zip
#
# It would be nice if our phones could show NPA-NXX in the event CallerID
# Name was empty.
#
(awk -F'	' '{print $2, $5, $1}' < allutlzd.txt | tail +2 | sed 's:^\([0-9]*\)-\([0-9]*\):\1\2:;s:^\([0-9]*\)  :\1 UNKNOWN:;s: * \(..\) $:, \1:g; s:^\([0-9]*\) \(.*\):database put znpanxx \1 "\2":' )| (
	while read line; do
		/pbx/usr/sbin/asterisk -rx "${line}"
	done
)

That'll load up the database with entries like

/znpanxx/201863                                   : UNION CITY, NJ
/znpanxx/201864                                   : UNION CITY, NJ
/znpanxx/201865                                   : UNION CITY, NJ
/znpanxx/201866                                   : UNION CITY, NJ
/znpanxx/201867                                   : UNION CITY, NJ
/znpanxx/201868                                   : UNION CITY, NJ
/znpanxx/201869                                   : UNION CITY, NJ

Then you merely have something like

% cat extensions.conf
[...]

[macro-set-cidn-npanxx]
exten=s,1,SetVar(npanxxsearch=unknown)
exten=s,2,GotoIf($["${LEN(${ARG1})}" = "10"]?3:5)
exten=s,3,SetVar(npanxxsearch=${ARG1:0:5})
exten=s,4,Goto(7)
exten=s,5,GotoIf($["${LEN(${ARG1})}" = "11"]?6:7)
exten=s,6,SetVar(npanxxsearch=${ARG1:1:6})
exten=s,7,GotoIf($[${LEN(${CALLERIDNAME})} = "0"]?10:8)
exten=s,8,DBget(npanxx=znpanxx/${npanxxsearch}) ; Get NPA-NXX.  If none, go to 109.
exten=s,9,SetCIDName(${npanxx})
exten=s,10,NoOp(CALLERID=${CALLERID} LEN ARG1 = ${LEN(${ARG1})})
exten=s,109,SetVar(npanxx="Unknown ${ARG1}");
exten=s,110,Goto(9)

[...]

[an-incoming-context]
[...]
exten => s,4,Macro(set-cidn-npanxx, ${CALLERIDNUM}) ; Set NPANXX CID
exten => s,5,LookupCIDName              ; Look up Caller-ID name in database
[...]

so that LookupCIDName will still override this.

Yeah, it bloats the built-in database by quite a bit, but it was cheap and
easy, and seems to work for the small number of cases where we don't have
a caller's name in the cidname database.  It is not particularly rigorous
and there are obviously other ways to do it.

It is also worth noting that some of the city names show up as other stuff,
like this:

/znpanxx/414973                                   : MILWAUKZN4, WI
/znpanxx/414974                                   : MILWAUKZN3, WI
/znpanxx/414975                                   : MILWAUKZN1, WI
/znpanxx/414976                                   : MILWAUKZN5, WI

which is mildly confusing to non-telephony folks, but still better than
not getting anything at all, IMHO.

... JG
-- 
Joe Greco - sol.net Network Services - Milwaukee, WI - http://www.sol.net
"We call it the 'one bite at the apple' rule. Give me one chance [and] then I
won't contact you again." - Direct Marketing Ass'n position on e-mail spam(CNN)
With 24 million small businesses in the US alone, that's way too many apples.



More information about the asterisk-users mailing list