-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShowProcFields
More file actions
executable file
·76 lines (61 loc) · 2.55 KB
/
ShowProcFields
File metadata and controls
executable file
·76 lines (61 loc) · 2.55 KB
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
#!/usr/bin/env python
"""Print all the fields for the indicated /proc/net file"""
import sys
import ProcHandlers
if sys.platform == "darwin":
print "MacOS doesn't have a '/proc' filesystem, quitting."
sys.exit(0)
def show_recs_from_one_file( ioh, proc_file):
"""Display all fields in all lines of the given file."""
seq = 0
active = ioh(proc_file)
for srec in active:
seq = seq + 1
if len(active.field) > 0:
print "- Record {seq} fields {size} hilit {subset}".format(seq=seq,
size=len(active.field), subset=len(srec))
fseq = 0
for off in active.field:
fseq = fseq + 1
currval = active.field[off]
if type(currval) == dict:
print "- - {seq}. {key} ...({size})".format(seq=fseq,
key=off, size=len(currval))
subseq = 0
for subent in currval:
subseq = subseq + 1
__templ = "- - - {seq}.{subseq}. {subkey} : {subval}"
if type(subent) == str:
print __templ.format(seq=fseq, subseq=subseq,
subkey=subent,
subval=str(currval[subent]))
else:
__skey = str(subent)
print __templ.format(seq=fseq, subseq=subseq,
subkey=__skey,
subval=str(currval[subent]))
else:
print "- - {seq}. {key} : {keyval}".format(seq=fseq,
key=off, keyval=str(currval))
return
if len(sys.argv) > 1:
TARGET = sys.argv[1]
else:
TARGET = "/proc/net/tcp"
if TARGET == "all":
for TARGET in ProcHandlers.FILE_HANDLER_REGISTRY:
print "- Logical records from {file} using {handler}".format(
file=TARGET,
handler=str(ProcHandlers.FILE_HANDLER_REGISTRY[TARGET]))
show_recs_from_one_file(
ProcHandlers.FILE_HANDLER_REGISTRY[TARGET], TARGET)
print ""
else:
HANDLER = ProcHandlers.GET_HANDLER(TARGET)
NOHANDLER = ProcHandlers.GET_HANDLER("null")
if HANDLER == NOHANDLER:
print "- No handler available for file {file}".format(file=TARGET)
else:
print "- Logical records from {file} using {handler}".format(
file=TARGET, handler=str(HANDLER))
show_recs_from_one_file( HANDLER, TARGET)