Skip to content

Commit d7d9d41

Browse files
authored
Merge pull request #131 from destan0098/patch-1
Create new nGraph.py
2 parents a34edc4 + 5ef97b4 commit d7d9d41

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lib/lib/nGraph/new nGraph.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import yaml
2+
import datetime
3+
import argparse
4+
import os
5+
from pyvis.network import Network
6+
7+
def init_argparse():
8+
parser = argparse.ArgumentParser(
9+
usage="%(prog)s --domain example.com --file vhost.yaml",
10+
description="Generate Network Graph For Sudomy."
11+
)
12+
parser.add_argument('--domain', type=str)
13+
parser.add_argument('--file', type=str, help="File in yaml format")
14+
return parser
15+
16+
parser = init_argparse()
17+
args = parser.parse_args()
18+
19+
if args.file is None or args.domain is None:
20+
parser.print_help()
21+
exit(0)
22+
23+
main_domain = args.domain
24+
report_path = os.path.dirname(args.file)
25+
26+
try:
27+
domain_data = yaml.safe_load(open(args.file))
28+
except:
29+
print("ERROR: File Is Not In Valid Yaml")
30+
exit(-1)
31+
32+
net = Network(height="1000px", width="100%", bgcolor="#2d2e2e", font_color="white", notebook=True)
33+
34+
net.add_node(main_domain, color="#162347", label=main_domain, group=main_domain, labelHighlightBold=True)
35+
36+
for ip in domain_data:
37+
net.add_node(ip, label=ip, color="#bf281d", group=ip, physics=True, labelHighlightBold=True)
38+
net.add_edge(ip, main_domain, title=main_domain, arrowStrikethrough=True, width=3)
39+
40+
for domain in domain_data.get(ip):
41+
net.add_node(domain, label=domain, title=domain, color="#828282", physics=True, group=domain, labelHighlightBold=True)
42+
net.add_edge(domain, ip, title=ip)
43+
44+
d = datetime.date.today()
45+
date_now = '{}-{}-{}'.format(d.strftime('%m'), d.strftime('%d'), d.strftime('%Y'))
46+
output_directory = "{}/{}-nGraph_{}".format(report_path, main_domain, date_now)
47+
48+
os.makedirs(output_directory, exist_ok=True)
49+
net.write_html("{}/{}-nGraph_{}.html".format(output_directory, main_domain, date_now))
50+
51+
print(f"Network graph saved to {output_directory}/{main_domain}-nGraph_{date_now}.html")

0 commit comments

Comments
 (0)