3 from time
import strftime
;
5 def SipSocket(host
='localhost', port
=5300):
7 so
.connect((host
, port
))
10 def login(so
, uname
='scclient', passwd
='clientpwd', locn
='The basement',
12 port
= so
.getpeername()[1]
14 resp
= send(so
, '9300CN%s|CO%s|CP%s|' % (uname
, passwd
, locn
), seqno
)
15 print "Received", repr(resp
)
16 print "Verified: ", verify(resp
)
18 raise "Logging in is only support for the raw transport on port 5300"
20 def send(so
, msg
, seqno
=0):
22 msg
+= 'AY' + str(seqno
)[0] + 'AZ'
23 msg
+= ('%04X' % calculate_cksum(msg
))
25 print 'Sending', repr(msg
)
28 return resp
, verify(resp
)
30 def calculate_cksum(msg
):
31 return (-reduce(operator
.add
, map(ord, msg
)) & 0xFFFF)
34 return(strftime("%Y%m%d %H%M%S"))
37 if msg
[-1] == '\r': msg
= msg
[:-2]
38 if msg
[-6:-4] == 'AZ':
39 cksum
= calculate_cksum(msg
[:-4])
40 return (msg
[-4:] == ('%04X' % cksum
))
41 # If there's no checksum, then the message is ok