[Asterisk-Users] Caller ID lookup via anywho.com

Nathan E. Pralle tarsi at binhost.com
Tue Nov 1 13:56:15 MST 2005


Tom,

I just took that script and shaved it down to something extra simple 
because I got tired of the crap in it.  It seems to work for me, 
although not a lot of the numbers around here have lookups.  Give it a 
shot, see what you think.

Attached as "mincallerid.pl".

Nathan

Tom Vile wrote:
> I found this agi script here on the list calleridnamelookup.agi but cant 
> seem to
> get it to work at all.  I see it launch the script but it returns 0 and 
> never queries
> anywho.com <http://anywho.com>.  I also noticed that some people have 
> had the same problem but
> no successful responses have been made.


-- 
-------------------------------------
Nathan E. Pralle
Give the Director a Serpent Deflector
www.nathanpralle.com
-------------------------------------
-------------- next part --------------
#!/usr/bin/perl -w

use Asterisk::AGI;
use LWP::UserAgent;

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();

my $callerid 		= $input{'callerid'};

$AGI->verbose("CALLERID IS: $callerid\n");

if ($callerid =~ /^(\d{3})(\d{3})(\d{4})$/) {
	$npa = $1;
	$nxx = $2;
	$station = $3;
	$AGI->verbose("Checking $npa $nxx $station...\n");
} 
else {
	$AGI->verbose("Unable to parse phone number for NPA/NXX/station.\n");
	exit(0);
}

#$npa='641';
#$nxx='892';
#$station='8019';

if ($name = &anywho_lookup ($npa, $nxx, $station)) {
	$newcallerid = "\"$name <$npa$nxx$station>\"";
	$AGI->set_callerid($newcallerid);
}
else{
	$AGI->verbose("Unable to find a lookup.");
}

exit(0);

sub anywho_lookup {
	my ($npa, $nxx, $station) = @_;
	my $ua = LWP::UserAgent->new( timeout => 45);
	my $URL = 'http://www.anywho.com/qry/wp_rl';
	$URL .= '?npa=' . $npa . '&telephone=' . $nxx . $station;
	$ua->agent('AsteriskAGIQuery/1');
	my $req = new HTTP::Request GET => $URL;
	my $res = $ua->request($req);
	if ($res->is_success()) {
		if ($res->content =~ /<!-- listing -->(.*)<!-- \/listing -->/s) {
			my $listing = $1;
			if ($listing =~ /<B>(.*)<\/B>/) { 
				my $clidname = $1;
				return $clidname;
			}

		}
	}
	return '';
}
-------------- next part --------------
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.12.7/153 - Release Date: 11/1/2005


More information about the asterisk-users mailing list