File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed
Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ A small utility to convert Unix `lsof` output to a graph showing FIFO and UNIX i
55Generate graph:
66
77```` shell
8- sudo lsof -n -F | ./ lsofgraph | dot -Tjpg > /tmp/a.jpg
8+ sudo lsof -n -F | python lsofgraph.py | dot -Tjpg > /tmp/a.jpg
99````
1010
1111or add ` unflatten ` to the chain for a better layout:
1212
1313```` shell
14- sudo lsof -n -F | ./ lsofgraph | unflatten -l 1 -c 6 | dot -T jpg > /tmp/a.jpg
14+ sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T jpg > /tmp/a.jpg
1515````
1616
1717![ example output] ( /example.jpg )
Original file line number Diff line number Diff line change @@ -43,7 +43,6 @@ def parse_lsof():
4343 proc = {}
4444 file = None
4545 cur = None
46-
4746 return procs
4847
4948
@@ -96,7 +95,7 @@ def find_connections(procs):
9695 else :
9796 fs [id ] = []
9897 fs [id ].append (file )
99-
98+
10099 if 't' in file and (file ['t' ] == 'IPv4' or file ['t' ] == 'IPv6' ):
101100 if '->' in file ['n' ]:
102101 a , b = file ['n' ].split ("->" )
@@ -118,7 +117,6 @@ def find_connections(procs):
118117 else :
119118 fs [id ] = []
120119 fs [id ].append (file )
121-
122120 return cs
123121
124122
@@ -128,7 +126,7 @@ def print_graph(procs, conns):
128126 'unix' : "purple" ,
129127 'tcp' : "red" ,
130128 'udp' : "orange" ,
131- 'pipe' : "orange "
129+ 'pipe' : "blue "
132130 }
133131
134132 # Generate graph
@@ -175,6 +173,7 @@ def print_graph(procs, conns):
175173 print ("}" )
176174
177175
178- procs = parse_lsof ()
179- conns = find_connections (procs )
180- print_graph (procs , conns )
176+ if __name__ == '__main__' :
177+ procs = parse_lsof ()
178+ conns = find_connections (procs )
179+ print_graph (procs , conns )
You can’t perform that action at this time.
0 commit comments