-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAS2805_Client.py
More file actions
130 lines (112 loc) · 3.38 KB
/
AS2805_Client.py
File metadata and controls
130 lines (112 loc) · 3.38 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import socket
import sys
import time
from datetime import datetime
from AS2805 import AS2805
from AS2805Errors import *
# Configure the client
#serverIP = "196.26.173.115"
#serverPort = 50089
serverIP = "127.0.0.1"
serverPort = 9002
numberEcho = 1
timeBetweenEcho = 5 # in seconds
bigEndian = True
#bigEndian = False
s = None
for res in socket.getaddrinfo(serverIP, serverPort, socket.AF_UNSPEC, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error, msg:
s = None
continue
try:
s.connect(sa)
except socket.error, msg:
s.close()
s = None
continue
break
if s is None:
print 'Could not connect :('
sys.exit(1)
def Alaric_Login():
res = False
d = datetime.now()
iso = AS2805(debug=False)
iso.setMTI('0800')
iso.setBit(7, d.strftime("%m%d%H%M%S"))
iso.setBit(11, '000001')
iso.setBit(12, d.strftime("%H%M%S"))
iso.setBit(13, d.strftime("%m%d"))
iso.setBit(70, '001')
try:
message = iso.getNetworkISO()
s.send(message)
print 'Sending ... %s' % message
ans = s.recv(2048)
print "Response = %s" % ans
isoAns = AS2805()
isoAns.setNetworkISO(ans)
v1 = isoAns.getBitsAndValues()
for v in v1:
print 'Bit %s of type %s with value = %s' % (v['bit'], v['type'], v['value'])
if isoAns.getMTI() == '0810':
if isoAns.getBit(39) == '00':
print "0800 Login sucessful"
res = True
else:
print "0800 Response Code = %s, Login Failed" % (isoAns.getBit(39),)
else:
print "Could not login with 0800"
except InvalidAS2805, ii:
print ii
return res
def Alaric_KeyExchange():
print "PostBridge_KeyExchange()"
res = False
d = datetime.now()
iso = AS2805(debug=False)
iso.setMTI('0800')
iso.setBit(7, d.strftime("%m%d%H%M%S"))
iso.setBit(11, '000001')
iso.setBit(12, d.strftime("%H%M%S"))
iso.setBit(13, d.strftime("%m%d"))
iso.setBit(70, '101')
try:
message = iso.getNetworkISO()
s.send(message)
print 'Sending ... %s' % message
ans = s.recv(2048)
print "Response = %s" % ans
isoAns = AS2805()
isoAns.setNetworkISO(ans)
v1 = isoAns.getBitsAndValues()
for v in v1:
print 'Bit %s of type %s with value = %s' % (v['bit'], v['type'], v['value'])
if isoAns.getMTI() == '0810':
if isoAns.getBit(39) == '00':
print "0800 Key Exchange sucessful"
Value = isoAns.getBit(125)[3:]
Key = Value[0:32]
Check = Value[32:]
print "Key = %s, Check = %s" % (Key, Check,)
res = True
else:
print "0800 Response Code = %s, Key Exchange Failed" % (isoAns.getBit(39),)
else:
print "Could not key exchange with 0800"
except InvalidAS2805, ii:
print ii
if __name__ == '__main__':
if Alaric_Login():
Alaric_KeyExchange()
s.settimeout(5)
print "timeout = %s" % (s.gettimeout())
while (True):
try:
ans = s.recv(2048)
except socket.error as e:
print "%s, Noting Received, Error = %s" % (datetime.now(), e)
time.sleep(10)