#!/usr/bin/expect log_user 0 spawn /usr/local/bin/baresip expect "registered successfully" send_user "I: Waiting for calls...\n" set timeout -1 #exp_internal 1 trap { exp_send "/quit\r" expect eof send_user "Bye\n" exit } {SIGINT SIGTERM} proc drop_call {} { exp_send "/accept\r" expect "call: answering call on line" sleep 15 exp_send "/hangup\r" expect "terminated" return } proc handle_call number { set now [clock seconds] send_user "I: Call from $number at [clock format $now -format {%d/%m/%Y %T}]\n" if [string match {+91*} $number] { send_user "Indian spam\n" drop_call } return } # sip:+44208xxxxxxxx@voiceless.aa.net.uk: Incoming call from: 07973 xxxxxx sip:07973xxxxxx@voiceless.aa.net.uk expect { -re " sip:(.*)@voiceless.aa.net.uk - audio-video" { handle_call $expect_out(1,string) exp_continue } } #send "exit\r" #expect eof