forked from Jatin1998/Basic-Python-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph2.py
More file actions
executable file
·53 lines (44 loc) · 1.71 KB
/
graph2.py
File metadata and controls
executable file
·53 lines (44 loc) · 1.71 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
#!/usr/bin/env python3.6 -u
# Copyright?
# Author: xxxxx xx@asdf.com
import argparse
__version__ = '0.1'
def do(filename, maxlines):
"""
Do function does ...
Param 1:
"""
f = open(filename)
line = f.readline()
# Avoid the header
line = f.readline()
print('digraph graphname {')
line_number = 0
prev_dip = ''
while line and line_number <= maxlines :
fields = line.split(',')
dip = fields[6]
if args.debug > 0:
print('Prev_dip: {}, dip: {}'.format(prev_dip,dip))
if prev_dip:
print('\t\"{}\" -> \"{}\";'.format(prev_dip,dip))
prev_dip = dip
line = f.readline()
line_number += 1
print('}')
####################
# Main
####################
if __name__ == '__main__':
# Parse the parameters
parser = argparse.ArgumentParser(description="Program xxx version {}. Author: xxx".format(__version__), usage='%(prog)s -n <screen_name> [options]')
parser.add_argument('-v', '--verbose', help='Amount of verbosity. This shows more info about the results.', action='store', default=0, required=False, type=int)
parser.add_argument('-d', '--debug', help='Amount of debugging. This shows inner information about the flows.', action='store', default=0, required=False, type=int)
parser.add_argument('-f', '--filename', help='File.', action='store', required=False)
parser.add_argument('-m', '--maxlines', help='Max lines to process.', action='store', type=int, default=200, required=False)
args = parser.parse_args()
if args.filename:
if args.verbose > 0:
print('File: {}'.format(args.filename))
do(args.filename, args.maxlines)
# Print a dot of ips relationships