-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprocessList.py
50 lines (46 loc) · 1.2 KB
/
processList.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
import subprocess
import admin, sys
from admin import checkPrivilege
from collections import defaultdict
import re
def netstat_b_o():
#print "\n*****************************************************************************************"
checkPrivilege()
# subprocess.call("netstat -b -o")
try:
x = "kooko"
print x
x = subprocess.Popen("netstat -b -o",stdout=subprocess.PIPE)
# print x.stdout.read()
text = x.stdout.read()
# x = subprocess.check_output("cmd -command \"netstat -e -o\"")
except:
print "============>>> ",x
# print "+++++++++++++++",x," .. ",text
return text
def TCP_List():
x=netstat_b_o()
print x
grp = re.findall(r'\[([a-zA-Z.]*)\]',x)
print grp
exe = list()
for i in grp:
exe.append(i)
# print i," --> ",
# print '\n',exe
return exe
def ProcessTable(Plist):
d = dict()
for element in Plist:
if element in d:
# increments the number in the list
d[element][0] += 1
else:
# creates a new list
d[element] = []
d[element].append(1)
# sorted(d, key = lambda k: k[0])
return d
def getProcessTable():
tex = TCP_List()
return ProcessTable(tex)