#!/usr/bin/perl -w #This perl script was developed by Tom Vile at Baldwin Technology Solutions, it was first #posted on nerd vittles: http://nerdvittles.com/index.php?p=82 # use Asterisk::AGI; use LWP::UserAgent; use DBI; $AGI = new Asterisk::AGI; $Fonetastic = '1' ; $AnyWho = '1' ; $Google = '1' ; $Asteridex = '0' ; my %input = $AGI->ReadParse(); my $callerid = $input{'calleridnum'}; my $calleridfull = $input{'callerid'}; if($callerid eq ''){ $callerid=$input{'callerid'}; } if(substr($callerid,0,1) eq '1'){ $callerid=substr($callerid,1); } if(substr($callerid,0,2) eq '+1'){ $callerid=substr($callerid,2); } $calleridfull =~ s/[\,\"\']+/ /g; $AGI->verbose("CALLERID IS: $calleridfull\n",1); if ($callerid =~ /^(\d{3})(\d{3})(\d{4})$/) { $npa = $1; $nxx = $2; $station = $3; $AGI->verbose("Checking $npa $nxx $station...\n",1); } elsif($callerid=~/\<(\d{3})(\d{3})(\d{4})\>/){ $npa = $1; $nxx = $2; $station = $3; $AGI->verbose("Checking $npa $nxx $station...\n",1); } else { $AGI->verbose("Unable to parse phone number for NPA/NXX/station. Phone number is: $callerid\n",1); exit(0); } #$npa='641'; #$nxx='892'; #$station='8019'; if ($Fonetastic > '0') { $AGI->verbose("Ready for Fonetastic.US lookup... \n",1); if ($name = &fonetastic_lookup ($npa, $nxx)) { $newcallerid = "\"$name <$npa$nxx$station>\""; $AGI->set_callerid($newcallerid); $AGI->verbose("Fonetastic.US match. New CallerIDName = $name\n",1); } else{ $AGI->verbose("Unable to find a Fonetastic.US match.\n",1); } }else{ $AGI->verbose("Fonetastic.US lookup disabled.\n",1); } if ($AnyWho > '0') { $AGI->verbose("Ready for AnyWho lookup... \n",1); if ($name = &anywho_lookup ($npa, $nxx, $station)) { $newcallerid = "\"$name <$npa$nxx$station>\""; $AGI->set_callerid($newcallerid); $AGI->verbose("AnyWho match. New CallerIDName = $name\n",1); } else{ $AGI->verbose("Unable to find an AnyWho lookup.\n",1); } }else{ $AGI->verbose("AnyWho lookup disabled.\n",1); } if ($Google > '0') { $AGI->verbose("Ready for Google lookup... \n",1); if ($name = &google_lookup ($npa, $nxx, $station)) { $newcallerid = "\"$name <$npa$nxx$station>\""; $AGI->set_callerid($newcallerid); $AGI->verbose("Google match. New CallerIDName = $name\n",1); } else{ $AGI->verbose("Unable to find a Google Phonebook match.\n",1); } }else{ $AGI->verbose("Google lookup disabled.\n",1); } if ($Asteridex > '0') { $AGI->verbose("Ready for AsteriDex lookup... \n",1); if ($name = &asteridex_lookup ($npa, $nxx, $station)) { $newcallerid = "\"$name <$npa$nxx$station>\""; $AGI->set_callerid($newcallerid); $AGI->verbose("AsteriDex match. New CallerIDName = $name\n",1); } else{ $AGI->verbose("Unable to find an AsteriDex match.\n",1); } }else{ $AGI->verbose("Asteridex lookup disabled.\n",1); } exit(0); sub fonefinder_lookup { my ($npa, $nxx) = @_; my $ua = LWP::UserAgent->new( timeout => 45); my $URL = 'http://www.fonefinder.net/findome.php?npa=' . $npa . '&nxx=' . $nxx . '&thoublock=&usaquerytype=Search+by+Number&cityname='; $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)'); my $req = new HTTP::Request GET => $URL; my $res = $ua->request($req); if ($res->is_success()) { if ($res->content =~ /areacode=(.+)H3>/) { my $listing = substr($1,22); #print $listing ; if ($listing =~ />(.+)npamap/) { my $clidcity = substr($1,0,-20); #print $clidcity ; if ($listing =~ /