-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprotousbtest.py
executable file
·87 lines (59 loc) · 2.5 KB
/
protousbtest.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
#! /usr/bin/env python
import commands
import string
import sys
import os
import time
usbTestCommand = './usbtest -t usb -a <ip>:8321 | tee <ip>.tmp'
rmCommand = "rm <ip>.tmp"
#processCommand = 'grep -i "got status" <ip>.tmp | grep -v -i "enoent" | grep -v -i "epipe" | wc -l'
#processCommand = 'grep -i "got status" <ip>.tmp | grep -v -i "enoent" | grep -v -i "epipe" | grep -v -i "eproto" |wc -l'
protoGrepCommand = 'egrep -i "port error on port| 500 msec" <ip>.tmp | wc -l'
mouseGrepCommand = 'grep -i "found mouse" <ip>.tmp | wc -l'
keyboardGrepCommand = 'grep -i "found keyboard" <ip>.tmp | wc -l'
flashGrepCommand = 'grep -i " Unknown device with address" <ip>.tmp | wc -l'
# handle arguments
if (len(sys.argv) != 2):
print "Usage: prototest.py <ip>"
print "TEST FAILED"
sys.exit(1)
# should do a reg expression to make sure the ip is ok....
pano_ip = sys.argv[1]
#print "Running USB protocol test on %s" % pano_ip
print "Running all USB tests on %s" % pano_ip
# kick off the protocol error test... with a grep...feed it into a word count
usbTestCommand = string.replace(usbTestCommand, "<ip>", pano_ip)
rmCommand = string.replace(rmCommand, "<ip>", pano_ip)
protoGrepCommand = string.replace(protoGrepCommand, "<ip>", pano_ip)
mouseGrepCommand = string.replace(mouseGrepCommand, "<ip>", pano_ip)
keyboardGrepCommand = string.replace(keyboardGrepCommand, "<ip>", pano_ip)
flashGrepCommand = string.replace(flashGrepCommand, "<ip>", pano_ip)
os.system(usbTestCommand)
time.sleep(30) # extra time to clear out the io buffers, finish tests, etc.
protoResult = commands.getoutput(protoGrepCommand)
mouseResult = commands.getoutput(mouseGrepCommand)
keyboardResult = commands.getoutput(keyboardGrepCommand)
flashResult = commands.getoutput(flashGrepCommand)
#print "Protocol Errors detected from %s: %s" % (pano_ip, processResult)
print "Port Errors detected from %s: %s" % (pano_ip, protoResult)
mouseDetected = 0
keyboardDetected = 0
flashDetected = 0
if (int(mouseResult) > 0):
print "Mouse Detected"
mouseDetected = 1
if (int(keyboardResult) > 0):
print "Keyboard Detected"
keyboardDetected = 1
if (int(flashResult) > 0):
print "USB Memory Detected"
flashDetected = 1
# check for zeros in the word count
if (string.strip(protoResult) == "0" and mouseDetected == 1 and keyboardDetected == 1 and flashDetected == 1):
# TEST PASSED on a match of zero
print "Test has PASSED"
else:
# TEST FAILED on a match of anything else
print "Test has FAILED"
os.system(rmCommand)
sys.exit(0)