Blocking Spammer By CallerID “name”

Home » Asterisk Users » Blocking Spammer By CallerID “name”
Asterisk Users 8 Comments

I have a subroutine to block spammer by CALLERID(number)

exten => 4,1,GotoIf(${BLACKLIST()}?blacklisted,s,1)
exten => 4,n,Set(goaway=${CALLERID(number):0:2})
exten => 4,n,GotoIf($[“${goaway}” = “V4” ]?blacklisted,s,1)
exten => 4,n,GotoIf($[“${goaway}” = “V3” ]?blacklisted,s,1)

but I just got another spammer (automated calls) who rotates his callerID number that starts with valid area code so blocking by prefix is not practical but it seems to me he uses the same (or few same) caller name like:

“Brit. Columbia “” <16047726633>”
“KHAN SHARON “” <16042984429>”
“Brit. Columbia “” <16042231781>“

So I was thinking the same subroutine can be used to block by CALLERID(name), isn’t it:

exten => 4,n,Set(goaway2=${CALLERID(name):0:11})
exten => 4,n,GotoIf($[“${goaway2}” = “Brit. Colum” ]?blacklisted,s,1)
exten => 4,n,GotoIf($[“${goaway2}” = “KHAN SHARON” ]?blacklisted,s,1)

The spammer is soliciting lowering credit card interest charges etc. anybody know who it is :-/

8 thoughts on - Blocking Spammer By CallerID “name”

  • Google the number and you can probably find other complaints and possibly who it is. Not that it will matter, there’s nothing you can do but block it.

    My approach to call filtering is:

    Deny All Allow Some

    I have a whitelist of callers I always want to accept that may include businesses outside my local area code. If my dialplan doesn’t recognize the incoming number I send them to a voicemail mail where they have to press “5” to leave a message. That knocks out the robo dialers. Then I google the number and if it’s a spammer, I add them to a blacklist where the call is dropped immediately. Really no point in playing funny or cute messages to them or even telling them they are blacklisted because it’s usually an auto-dialer and a real person doesn’t hear it anyway.

  • Thank you for input. Good idea, I like your approach with press “number” to leave a message”, this will definitely cut the robo-calls voice-mail. Do you use database for white-list?
    Can you post a section of your dial plan that deals with blocking?

    This is a medical clinic so white-list, black-list is not a good solution but it might be good for home use.


  • I do this, but without any white or black lists, and it works great. The greeting says “press one for , or two for “. That alone is enough to knock out virtually all the spammers (99% of them are robo-calls these days). Once 1 or 2 is pressed, the phones in the house will ring with a different ring code for each, and if there’s no answer, the call goes to separate voice mail boxes for my wife and myself. Works great. That alone was worth the effort to install asterisk. Now, the cost of the telephony card, that’s a different story. Never before have I had a PCI card that costs more than the rest of the machine combined. So I really wouldn’t have done this if it weren’t such a cool geek project 🙂


  • Greg, would you mind posting your dialplan? I think it would be useful and instructive for newbies like me. Thanks.

  • It may be a day or two before I can do that, as of course I will need to sanitize it (remove passwords, commented lines, etc.)


  • When I play:
    exten => s,n,Background(welcome)
    and press extension “1” the system will not jump to this extension immediately, there is a few sec. pause.

    I think because I have an extensions “1” and “11” in my system. Is there a way to tell “Background” to execute the first match?

    I see there are two options: ‘s’ and ‘m’ but none of them return immediately

    I put voicemail on exten ‘0’ (nothing else starts with ‘0’) but when the message is playing and I hit ‘0’
    there is a two or three seconds pause before the Voicemail box rings. Is there a way to jump to extension immediately?

    exten => 1,n,Background(T-to-leave-msg)
    exten => 1,n,Background(press-0)
    exten => 1,n,WaitExten(5)

    exten => 0,1,Voicemail(11,b)
    exten => 0,n,Hangup()

  • Yeah, probably wouldn’t work too well in a business environment where you actually NEED to answer calls. I go to a lot of trouble to make sure people can’t get in touch with me. 🙂

    I keep my blacklist and whitelist in AstDB. However, I maintain it in a bash script so that I can update the script and then rebuild the AstDB very quickly. If I lose my AstDB I can just rebuild it with the script.

    ; Check the Asterisk database for blacklisted number
    exten => s,n,GotoIf(${DB_EXISTS(blacklisted/${CALLERID(num)})}?blacklisted,s,1)

    Whitelist can be done the same way:

    ; Check the Asterisk database for whitelisted number
    exten => s,n,GotoIf(${DB_EXISTS(whitelisted/${CALLERID(num)})}?voicemail,abc,1)

    I have a [screened] context that screens the calls and prompts for pressing “5”

    [screened] ;{{{
    exten => s,1,Zapateller()
    exten => s,n,Set(TSTAMP=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
    exten => s,n,NoOp(${TSTAMP})
    exten => s,n,Monitor(wav,${TSTAMP}-${CALLERID(num)}-screened,m)
    exten => s,n,Set(COUNT=1)
    exten => s,n(loop),WaitExten(1)
    exten => s,n,Background(privacy-screening-unidentified-calls)
    exten => s,n,WaitExten(.5)
    exten => s,n,Background(press-5)
    exten => s,n,Background(T-to-leave-msg)
    exten => s,n,WaitExten(3)
    exten => s,n,Set(COUNT=$[${COUNT} + 1])
    exten => s,n,GotoIf($[${COUNT} < = 3]?loop) exten => s,n,PlayBack(goodbye)
    exten => s,n,StopMonitor()
    exten => s,n,Hangup()

    exten => 5,1,NoOp(Pressed 5)
    exten => 5,n,PlayBack(tcg/pls-lv-msg-w-nam-phnnum)
    exten => 5,n,StopMonitor()
    exten => 5,n,GoSub(voicemail,tcg,1)
    exten => 5,n,Hangup()

    exten => i,1,Playback(option-is-invalid)
    exten => i,n,Goto(99,msg)


  • Mine looks like this:

    exten => s,1,Answer()
    exten => s,2,Set(TIMEOUT(digit)=1)
    exten => s,3,Background(greeting)
    exten => s,n,WaitExten(10)
    exten => s,n,Goto(3)

    I think setting the digit timeout does the trick for me. (My greeting file says at the end, “stay on the line and this menu will repeat”, and of course it does until the caller hangs up.