Python Scripts: Difference between revisions

Line 229:
if x !=0:
print x
except KeyboardInterrupt:
print("User killed command.")
</pre>
 
;Terminal Plot
sudo pip install terminalplot
<pre>
from terminalplot import plot
#import gnuplotlib as gp
import subprocess as sub
import re
 
x = 0
a = []
b = []
 
try:
p = sub.Popen(('sudo', 'tcpdump', '-l'), stdout=sub.PIPE)
for row in iter(p.stdout.readline, b''):
y = re.search('length (\d+)', row)
if y:
z = int(y.group(1))
if z != 0:
x += 1
print x
b.append(z)
a.append(x)
if x == 10:
plot(a,b)
print a
print b
# Remove below # if you don't want continuous output
# break
x = 0
a = []
b = []
 
except KeyboardInterrupt:
print("User killed command.")