I’m trying to create a SIP client that logs all the received calls.
I’m using Python with the pyVoIP library, this is the code:
from pyVoIP.VoIP import VoIPPhone, CallState, PhoneStatus, InvalidStateError
import time
import datetime
def answer(call): # This will be your callback function for when you receive a phone call
try:
print(call.state)
anum = call.request.headers["From"]["number"]
print(','+ datetime.datetime.now().strftime("%Y%m%d")+', '+ datetime.datetime.now().strftime("%X")+', '+ datetime.datetime.now().strftime("%f")+',,,,,,,'+anum+',0662279775,,,')
open('tmp.csv', 'w+')
f.write(','+ datetime.datetime.now().strftime("%Y%m%d")+', '+ datetime.datetime.now().strftime("%X")+', '+ datetime.datetime.now().strftime("%f")+',,,,,,,'+anum+',0662279775,,,')
print(anum)
call.answer()
call.hangup()
except InvalidStateError:
print(InvalidStateError)
pass
if __name__ == "__main__":
vp = VoIPPhone('79.98.45.133',5060,'0662279775','065+eMl6Ttd6$T',callCallback=answer)
print('VOIP PHONE INIZIALIZATED: status = '+str(vp._status))
vp.start()
print('VoIP PHONE STARTED: status = '+str(vp._status))
while(vp._status==PhoneStatus.REGISTERING or vp._status==PhoneStatus.INACTIVE):
continue
print('WHILE LOOP STATUS ENDED: status = '+str(vp._status))
input('Press ENTER to stop')
time.sleep(5)
vp.stop()
print('STOPPED VOIP PHONE: status = '+str(vp._status))
time.sleep(5)
The registration phase is ok, the client is able to register to the SIP Server so I get:
WHILE LOOP STATUS ENDED: status = PhoneStatus.REGISTERED
When I call the number associated to the SIP account sometimes the call is received by the client and sometime isn’t.
I made a trace of the SIP packet received by the client and I see that the SIP Server sends OPTIONS messages to the client but the client doesn’t answer to them.
I guess that this is the problem: the server doesn’t receive an answer to the OPTIONS messages so it thinks that the client is down so it doesn’t forward the call to the client.
Is there a way to configure pyVoIP to answer to OPTIONS messages?