-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetserial.py
89 lines (77 loc) · 2.25 KB
/
getserial.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
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
import bottle
from bottle import get, post, request, template, route
bottle.TEMPLATE_PATH.insert(0,'/var/www/cgi-bin/')
#@get('/getserial')
@route('/', method='GET')
def show_form():
return '''
<form action="/getserial" method="POST">
<div>
<label>IP address of device:</label>
<input type="text" name="ip"/>
</div>
<div>
<label>Type of device:</label>
<select name="type">
<option value="biamp_audia">Biamp Audia</option>
<option value="corio">Corio</option>
</select>
</div>
<input type="submit"/>
</form>'''
#@post('/getserial')
@route('/', method='POST')
def run():
type = request.forms.get('type')
address = request.forms.get('ip')
if type == 'biamp_audia':
import os
from socket import socket, AF_INET, SOCK_STREAM
import struct
import re
import sys
port = 12001
data = '000000100100000000010a000822000030010001'.decode('hex')
s = socket(AF_INET, SOCK_STREAM)
s.settimeout(5)
s.connect((address, port))
s.send(data.encode('utf-8'))
output = s.recv(32)
s.close()
output = output[17:32]
output = str(output)
serial = re.sub('[^0-9]','', output)
#return output, address, type
"""results"""
info = {'type' : type,
'serial' : serial,
'address' : address
}
return template('standard.tpl', info)
elif type == 'corio':
import telnetlib
serialcard = []
session = telnetlib.Telnet(address, 10001, 5)
#session.set_debuglevel(9) # enable telnet debugging
response = session.read_until("'login(username,password)'",5)
session.write("login(admin,adminpw)" + "\r\n")
response = session.read_until("!Info : User admin Logged In",5)
session.write("CORIOmax.Serial_Number" + "\r\n")
data = session.read_until("!Done", 1)
serial = data.splitlines()[1]
for x in range(1, 17):
session.write("Slots.Slot" + str(x) + ".Carddata" + "\r\n")
data = session.read_until("!Done", 1)
if "BaseNo" not in data:
continue
card = data.splitlines()[1]
serialcard.append(card)
info = {'type' : type,
'serial' : serial,
'serialcard' : serialcard,
'address' : address
}
return template('corio.tpl', info)
session.close()
application=bottle.default_app()
#bottle.run(host='s-scic-stats2', port=8000, debug=True) # run in a local test server