-
Notifications
You must be signed in to change notification settings - Fork 6
/
acstest.py
executable file
·61 lines (54 loc) · 1.9 KB
/
acstest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# Copyright (C) 2006-2008 Georgia Public Library Service
#
# Author: David J. Fiander
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
import operator
import socket
from time import strftime;
def SipSocket(host='localhost', port=5300):
so = socket.socket()
so.connect((host, port))
return so
def login(so, uname='scclient', passwd='clientpwd', locn='The basement',
seqno=0):
port = so.getpeername()[1]
if port == 5300:
resp = send(so, '9300CN%s|CO%s|CP%s|' % (uname, passwd, locn), seqno)
print "Received", repr(resp)
print "Verified: ", verify(resp)
else:
raise "Logging in is only support for the raw transport on port 5300"
def send(so, msg, seqno=0):
if seqno:
msg += 'AY' + str(seqno)[0] + 'AZ'
msg += ('%04X' % calculate_cksum(msg))
msg += '\r'
print 'Sending', repr(msg)
so.send(msg)
resp = so.recv(1000)
return resp, verify(resp)
def calculate_cksum(msg):
return (-reduce(operator.add, map(ord, msg)) & 0xFFFF)
def sipdate():
return(strftime("%Y%m%d %H%M%S"))
def verify(msg):
if msg[-1] == '\r': msg = msg[:-2]
if msg[-6:-4] == 'AZ':
cksum = calculate_cksum(msg[:-4])
return (msg[-4:] == ('%04X' % cksum))
# If there's no checksum, then the message is ok
return True