/
triage.py
executable file
·284 lines (251 loc) · 7.59 KB
/
triage.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#! /usr/bin/python
import subprocess
import sys
import os
#Check that lftp is installed
try:
subprocess.check_ouput(['lftp','--version'])
except:
os.system('sudo apt-get install lftp > /dev/null')
#Check that dmidecode is installed
try:
subprocess.check_output(['dmidecode', '--version'])
except:
subprocess.call(['sudo', 'apt-get', 'install', 'dmidecode'])
#Check if the triage sheet was entered as a command line argument
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = raw_input("Please enter CRT number: ")
#Just in case the user enters it as 'L12345.triage'
if not ".triage.txt" in filename:
filename = filename+ ".triage.txt"
#Create the triage file
txtfile = open(filename, "w")
#After looking at some computers I have decided to add an extra part to this script
#If the computer is not made by a main brand such as dell, ibm, hp, or lenovo
#The script will suggest manually entering certain values
#such as the serial number
#parsing output of dmidecode for manufacturer, model, and Serial number
manu = subprocess.check_output(['sudo', 'dmidecode', '-t', 'system'])
data = manu.splitlines()
for line in data:
if "Manufacturer" in line:
print "--------------------------"
txtfile.write("--------------------------\n")
print line.replace('\t','')
txtfile.write(line.replace('\t','')+"\n")
print "--------------------------"
txtfile.write("--------------------------\n")
if "Version" in line:
line = line.replace('\t','')
print line.replace("Version", "Model")
txtfile.write(line.replace("Version", "Model")+ "\n")
print "--------------------------"
txtfile.write("--------------------------\n")
if "Serial" in line:
print line.replace('\t','')
txtfile.write(line.replace('\t','') + "\n")
#variables for hardware devices
USB = False
ETHERNET = False
VGA = False
DVI = False
HDMI = False
PS2 = False
WIFI = False
#other ports
MIC = False
HEAD = False
#add firewire
#parsing lspci for hardware devices
data = subprocess.check_output(['sudo', 'dmidecode'])
data = data.splitlines()
usbCount = 0
for line in data:
if "External" in line:
if " USB " in line:
USB = True
usbCount = usbCount + 1
if "Ethernet" in line:
ETHERNET = True
if "PS/2" in line:
PS2 = True
if "Headphone" in line:
HEAD = True
if "Microphone" in line:
MIC = True
#NEEDS TESTED
if "DVI" in line:
DVI = True
#NEEDS TESTED
if "HDMI" in line:
HDMI = True
extra = subprocess.check_output(['lspci'])
extra =extra.splitlines()
for line in extra:
if "Network controller" in line:
WIFI = True
if "VGA compatible" in line:
VGA = True
print "--------------------------"
txtfile.write("--------------------------\n")
print "Video Devices:"
txtfile.write("Video Devices:\n")
if VGA:
print "-VGA"
txtfile.write("-VGA\n")
if DVI:
print "-DVI"
txtfile.write("-DVI\n")
if HDMI:
print "-HDMI"
txtfile.write("-HDMI\n")
print "--------------------------"
txtfile.write("--------------------------\n")
print "Ports:"
txtfile.write("Ports:\n")
if ETHERNET:
print "-ETHERNET"
txtfile.write("-ETHERNET\n")
if USB:
print "-USB x" + str(usbCount)
txtfile.write("-USB x" + str(usbCount) + "\n")
if PS2:
print "-PS/2"
txtfile.write("-PS/2\n")
print "--------------------------"
txtfile.write("--------------------------\n")
print "Other Ports:"
txtfile.write("Other Ports:\n")
if HEAD:
print "-Headphones port"
txtfile.write("-Headphones port\n")
if MIC:
print "-Microphone port"
txtfile.write("-Microphone port\n")
print "--------------------------"
txtfile.write("--------------------------\n")
hddsize = subprocess.check_output(['sudo', 'fdisk', '-l'])
hddsize = hddsize.splitlines()
for line in hddsize:
if "Disk /dev/sda" in line:
data2 = line
data2 = data2.split(" ")
print "Hard Drive: " + data2[2] + "GB"
txtfile.write("Hard Drive: " + data2[2] + "GB\n")
#variables for possible cd/dvd configurations
CD=False
DVD=False
CDR=False
DVDR=False
#NEEDS TO BE TESTED ON A COMPUTER WITHOUT A CD DRIVE
#I have a feeling the file would not exist so I
#wrapped it in a try except block, if it fails
#we assume there is no CD drive
try:
cdrom = subprocess.check_output(['cat', '/proc/sys/dev/cdrom/info'])
cdrom = cdrom.splitlines()
for line in cdrom:
if "play audio" in line and '1' in line:
CD=True
if "read DVD" in line and '1' in line:
DVD=True
if "write DVD-R" in line and '1' in line:
DVDR=True
if "write CD-RW" in line and '1' in line:
CDR=True
except:
CD=False
DVD=False
CDR=False
DVDR=False
print "--------------------------"
txtfile.write("--------------------------\n")
#if we can read cds and not dvds
if CD and not DVD:
print "CD/DVD Drive: CD"
txtfile.write("CD/DVD Drive: CD\n")
#if we can read, but not write cd/dvd
if CD and DVD and not CDR and not DVDR:
print "CD/DVD Drive: CD-DVD"
txtfile.write("CD/DVD Drive: CD-DVD\n")
#assumes that if we can write we can read
#if we can write cd but not dvd
if CDR and DVD and not DVDR:
print "CD/DVD Drive: CD-RW/DVD"
txtfile.write("CD/DVD Drive: CD-RW/DVD\n")
#if we can write both
if CDR and DVDR:
print "CD/DVD Drive: CD_RW/DVD-RW"
txtfile.write("CD/DVD Drive: CD_RW/DVD-RW\n")
#if it has no CD/DVD drive
if not CD and not CDR and not DVD and not DVDR:
print "CD/DVD Drive: N/A"
txtfile.write("CD/DVD Drive: N/A\n")
#This code is Ubuntu specific, if using another os it will
#throw an error
try:
osversion = subprocess.check_output(['more', '/etc/lsb-release'])
osversion = osversion.splitlines()
for line in osversion:
if "RELEASE" in line:
oss = line
print "--------------------------"
txtfile.write("--------------------------\n")
print "Final Ubuntu OS: " + oss.replace("DISTRIB_RELEASE=","")
txtfile.write("Final Ubuntu OS: " + oss.replace("DISTRIB_RELEASE=","")+ "\n")
except:
print "Not an ubuntu os, tell Kevin. Program exiting!"
exit
print "--------------------------"
txtfile.write("--------------------------\n")
#parse dmidecode for processor information
processor = subprocess.check_output(['sudo', 'dmidecode', '-t', 'processor'])
processor = processor.splitlines()
for line in processor:
if "Max Speed" in line:
line = line.replace('\t','')
print "Processor speed: " + line.replace("Max Speed: ","")
txtfile.write("Processor speed: " + line.replace("Max Speed: ","")+"\n")
print "--------------------------"
txtfile.write("--------------------------\n")
#Get and parse the RAM size from /proc/meminfo
#it is originally given in kB, so convert to MB
#by dividing by 1000
raminfo = subprocess.check_output(['cat', '/proc/meminfo'])
raminfo = raminfo.splitlines()
raminfo = raminfo[0].replace(" ","")
raminfo = raminfo.replace("kB","")
raminfo = raminfo.replace("MemTotal:","")
print "Memory: " + str(int(raminfo)/1000) + " MB"
txtfile.write("Memory: " + str(int(raminfo)/1000) + " MB\n")
print "--------------------------"
txtfile.write("--------------------------\n")
#check if computer is wifi enabled
#if the laptop is missing drivers this may
#give a false bas reading
if WIFI:
print "Wifi enabled"
txtfile.write("Wifi available\n")
else:
print "No wifi"
txtfile.write("No wifi\n")
print "--------------------------"
txtfile.write("--------------------------\n")
osbittype = subprocess.check_output(['uname', '-m'])
if 'i686' in osbittype:
print "OS type 32X/32Lite"
txtfile.write("OS type 32X/32Lite\n")
else:
print "OS type x86_64"
txtfile.write("OS type x86_64\n")
print "--------------------------"
txtfile.write("--------------------------\n")
aString = raw_input("Please enter any other comments: ")
txtfile.write("Comments:\n")
txtfile.write(aString)
txtfile.close()
executeThis = " -e \'cd /Public/triage;put " + filename + ";exit\'"
print executeThis
os.system("lftp 10.0.88.5" + executeThis)