Block Certain Numbers

Home » Asterisk Users » Block Certain Numbers
Asterisk Users 6 Comments

Hi.

i would like to manually create a list of numbers to block. these numbers are from spammers (advertizers). is there an easy way to send these particular numbers to busy or even drop the call?

6 thoughts on - Block Certain Numbers

  • Yes! Dead easy.

    Use an external script, written in your favourite language, to look up the number in some sort of database and return failure (exit 1) if it finds it there, or success (exit 0) if not. Call this with System() in dialplan. If the System() call succeeds (meaning the number was not found in the database), Asterisk will move onto the next priority; if it fails (meaning the number was in the database) then it will move on by an extra 100.

    Alternatively, you can read the value of ${SYSTEMSTATUS} to get the exit code.

  • hello

    if you have just some numbers to block you can use the below code in your dial plan

    exten => 5xx,1,NoOp(Caller-ID: ${CALLERID(all)})
    exten => 5xx,n,GotoIf($[“${CALLERID(num)}”=”0661xxxxxx” ]?3:4)
    exten => 5xx,n,hangup exten => 5xx,n,Dial(SIP/223, 30)

    2013/6/17 A J Stiles

  • i am using asterisk’s internal database to create a phonebook. i was thinking to create something similar for the blocking, but i got stuck on how to block the numbers.

  • Well, once you’ve worked out whether the caller is welcome or not, then you need to dial your phone if the caller is allowed; or just play a suitable message and then Hangup() if they aren’t.

    exten => s,1,NoOp(Incoming call from ${CALLERID(num)})
    exten => s,2,System(check_ban_db ${CALLERID(num)})
    ; goes to 3 if system cmd exited OK or 103 if exited non-zero exten => s,3,Dial(${MY_PHONE})
    exten => s,4,Hangup()
    ; step 103 is where we deal with unwelcome callers exten => s,103,Playback(f-off)
    exten => s,104,Hangup()

    You just need to make sure that you have a suitable message saved in
    /var/lib/asterisk/sounds/f-off.wav .

  • That seems suitable. for the cid name i am using asterisk’s internal database for the lookup such as
    *database put cidname 1111222333 “xyzwhoevername”*

    then how do you create the database for the check_ban_db?

  • However you like! I’d use a MySQL database, and my “check_ban_db” and
    “add_to_ban_db” scripts would be written in Perl or Bash. But that’s just because that’s what I’m familiar with. If you prefer Postgres and Python or PHP, or even flat text files and awk, by all means use that.

    Paid-for stuff isn’t welcome here, so you will have to contact me off-list if you want me to write it for you …..