AsteriskTech- The culture / technology / and evolution of

A social network and information resource for Asterisk enthusiasts

David Van Ginneken

Blocking Telemarketers in Asterisk with whocalled.us

Don't you wish there were a community driven database of telemarketers you could use to automatically block them? Well there is! The great people over at whocalled.us have just that, and they even provide a web API which allows you to check numbers against.

The code below will check the number against the API and assign the SPAM variable to yes if it has been reported more than 5 times. (Sorry about the code formatting in this post):


#!/usr/bin/perl
use strict;
use Asterisk::AGI;
use LWP::Simple qw($ua get);
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
#
# www.whocalled.us is a community driven database of telemarketers..
# Register on the whocalled.us website and enter your credentials here
my $whocalleduser = 'user';
my $whocalledpass = 'pass';
# How many reports to consider the number to be spam
my $wc_score = 5;
# No Need to change anything below here.
$ua->agent('Mozilla/4.0 (compatible; Telemarketer Lookup)');
my $callerid = $input{'callerid'};
# Validate it is a 10 digit number..
if ($callerid !~ /^\d{10}$/){
# Callerid Number is not 10 digits.. Mark it as spam..
$AGI->set_variable('SPAM', 'yes');
exit;
}
# Check the Whocalled.us WebSite
my $url = 'http://whocalled.us/do?action=getScore&name=' . $whocalleduser . '&pass=' . $whocalledpass. '&phoneNumber=' . $callerid;
my $output = get($url);
my ($score) = grep {/score/} split(/&/ , $output);
(undef,$score) = split(/=/, $score);
$score =~ s/\D//g;
$score = 0 unless $score =~ /^\d+$/;
if ($score >= $wc_score){
# Spam Call
$AGI->set_variable('SPAM', 'yes');
exit;
}
# Passed the spam checks
$AGI->set_variable('SPAM', 'unknown');

__END__

After calling the AGI, you can jump to voicemail, the telemarketer torture script, or whatever else you desire.

exten => _NXXNXXXXXX,1,AGI(whocalled.pl)
# AGI Script Sets the SPAM variable.
exten => _NXXNXXXXXX,n,GotoIf($["${SPAM}"="yes"]?block)
exten => _NXXNXXXXXX,n,Dial(some_extension)
exten => _NXXNXXXXXX,n(block),Voicemail(somevoicemail,u)

Add a Comment

You need to be a member of AsteriskTech- The culture / technology / and evolution of to add comments!

Join this network

About AsteriskTech- The culture / technology / and evolution of

Aaron Rosenthal Aaron Rosenthal created this social network on Ning.

Create your own social network!

© 2009   Created by Aaron Rosenthal on Ning.   Create your own social network

Report an Issue  |  Feedback  |  Privacy  |  Terms of Service