本文整理汇总了Python中AutoNetkit.get_dns_graph方法的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit.get_dns_graph方法的具体用法?Python AutoNetkit.get_dns_graph怎么用?Python AutoNetkit.get_dns_graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoNetkit
的用法示例。
在下文中一共展示了AutoNetkit.get_dns_graph方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import get_dns_graph [as 别名]
def plot(network, show=False, save=True):
""" Plot the network """
try:
import matplotlib.pyplot as plt
except ImportError:
LOG.warn("Matplotlib not found, not plotting using Matplotlib")
return
try:
import numpy
except ImportError:
LOG.warn("Matplotlib plotting requires numpy for graph layout")
return
plot_dir = config.plot_dir
if not os.path.isdir(plot_dir):
os.mkdir(plot_dir)
graph = network.graph
pos=nx.spring_layout(graph)
# Different node color for each AS. Use heatmap based on ASN
plot_graph(graph, title="Network", pos=pos, show=show, save=save,
node_color=cmap_index(network, graph))
graph = ank.get_ebgp_graph(network)
labels = dict( (n, network.label(n)) for n in graph)
plot_graph(graph, title="eBGP", pos=pos, labels=labels, show=show, save=save)
graph = ank.get_ibgp_graph(network)
labels = dict( (n, network.label(n)) for n in graph)
plot_graph(graph, title="iBGP", pos=pos, labels=labels, show=show, save=save)
graph = ank.get_dns_graph(network)
labels = dict( (n, network.label(n)) for n in graph)
plot_graph(graph, title="DNS", pos=pos, labels=labels, show=show, save=save)
示例2: plot
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import get_dns_graph [as 别名]
def plot(network, show=False, save=True):
""" Plot the network """
try:
import matplotlib.pyplot as plt
except ImportError:
LOG.warn("Matplotlib not found, not plotting using Matplotlib")
return
try:
import numpy
except ImportError:
LOG.warn("Matplotlib plotting requires numpy for graph layout")
return
plot_dir = config.plot_dir
if not os.path.isdir(plot_dir):
os.mkdir(plot_dir)
graph = network.graph
try:
#Extract co-ordinates to normalize (needed for PathDrawer, desired for neatness in plots)
x, y = zip(*[(d['x'], d['y']) for n, d in network.graph.nodes(data=True)])
x = numpy.asarray(x, dtype=float)
y = numpy.asarray(y, dtype=float)
#TODO: combine these two operations together
x -= x.min()
x *= 1.0/x.max()
y -= y.min()
y *= -1.0/y.max() # invert
y += 1 # rescale from 0->1 not 1->0
#TODO: see if can use reshape-type commands here
co_ords = zip(list(x), list(y))
co_ords = [numpy.array([x, y]) for x, y in co_ords]
nodes = [n for n in network.graph.nodes()]
pos = dict( zip(nodes, co_ords))
except:
pos=nx.spring_layout(graph)
# Different node color for each AS. Use heatmap based on ASN
paths = []
#paths.append( nx.shortest_path(network.graph, network.find("1a.AS1"), network.find("1c.AS1")))
#paths.append( nx.shortest_path(network.graph, network.find("1b.AS1"), network.find("1c.AS1")))
#paths.append(nx.shortest_path(network.graph, network.find("1a.AS1"), network.find("2c.AS2")))
#paths.append( nx.shortest_path(network.graph, network.find("as100r3.AS100"), network.find("as300r1.AS300")))
#paths.append(nx.shortest_path(network.graph, network.find("as100r2.AS100"), network.find("as30r1.AS30")))
#Node colors
legend = {
'shapes': [],
'labels': [],
}
colormap = cm.jet
unique_asn = sorted(list(set(d.asn for d in network.devices())))
asn_norm = colors.normalize(0, len(unique_asn))
asn_colors = dict.fromkeys(unique_asn)
for index, asn in enumerate(asn_colors.keys()):
asn_color = colormap(asn_norm(index)) #allocate based on index position
asn_colors[asn] = asn_color
legend['shapes'].append( plt.Rectangle((0, 0), 0.51, 0.51,
fc = asn_color))
legend['labels'].append( asn)
node_colors = [asn_colors[device.asn] for device in network.devices()]
plot_graph(graph, title="Network", pos=pos, show=show, save=save,
node_color=node_colors)
plot_graph(graph, title="Paths", pos=pos, show=show, save=save,
legend_data = legend,
paths = paths,
node_color=node_colors)
graph = ank.get_ebgp_graph(network)
labels = dict( (n, network.label(n)) for n in graph)
plot_graph(graph, title="eBGP", pos=pos, labels=labels, show=show, save=save)
graph = ank.get_ibgp_graph(network)
labels = dict( (n, network.label(n)) for n in graph)
plot_graph(graph, title="iBGP", pos=pos, labels=labels, show=show, save=save)
graph = ank.get_dns_graph(network)
labels = dict( (n, network.label(n)) for n in graph)
plot_graph(graph, title="DNS", pos=pos, labels=labels, show=show, save=save)
示例3: jsplot
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import get_dns_graph [as 别名]
#.........这里部分代码省略.........
labels = dict( (n, network.label(n)) for n in ebgp_graph)
nx.relabel_nodes(ebgp_graph, labels, copy=False)
ebgp_filename = os.path.join(jsplot_dir, "ebgp.js")
js_files.append("ebgp.js")
with open( ebgp_filename, 'w') as f_js:
f_js.write( js_template.render(
node_list = ebgp_graph.nodes(data=True),
edge_list = ebgp_graph.edges(data=True),
overlay_graph = True,
))
ibgp_graph = ank.get_ibgp_graph(network)
node_list = []
for node in ibgp_graph.nodes():
# Set label to be FQDN, so don't have multiple "Router A" nodes etc
data = { 'label': "%s (%s)" % (node.fqdn, network.graph.node[node].get("ibgp_level"))}
node_list.append( (node.fqdn, data))
edge_list = ibgp_graph.edges(data=True)
edge_list = list( (src.fqdn, dst.fqdn, data.get("rr_dir")) for (src, dst, data) in edge_list)
ibgp_filename = os.path.join(jsplot_dir, "ibgp.js")
js_files.append("ibgp.js")
with open( ibgp_filename, 'w') as f_js:
f_js.write( js_template.render(
node_list = node_list,
edge_list = edge_list,
physical_graph = True,
))
#TODO: clarify difference of physical_graph and overlay_graph
#TODO: see if js_files ever used
dns_graph = ank.get_dns_graph(network)
node_list = []
for node in dns_graph.nodes():
# Set label to be FQDN, so don't have multiple "Router A" nodes etc
data = { 'label': "%s (%s)" % (node.fqdn, dns_graph.node[node].get("level"))}
node_list.append( (node.fqdn, data))
dns_filename = os.path.join(jsplot_dir, "dns.js")
edge_list = dns_graph.edges(data=True)
#edge_list = list( (src.fqdn, dst.fqdn, data.get('dns_dir')) for (src, dst, data) in edge_list)
edge_list = list( (src.fqdn, dst.fqdn, '') for (src, dst, data) in edge_list)
js_files.append("dns.js")
with open( dns_filename, 'w') as f_js:
f_js.write( js_template.render(
node_list = node_list,
edge_list = edge_list,
physical_graph = True,
))
dns_auth_graph = ank.get_dns_auth_graph(network)
node_list = []
for node in dns_auth_graph.nodes():
# Set label to be FQDN, so don't have multiple "Router A" nodes etc
data = { 'label': "%s" % node.label}
node_list.append( (node.fqdn, data))
dns_filename = os.path.join(jsplot_dir, "dns_auth.js")
edge_list = dns_auth_graph.edges(data=True)
edge_list = list( (src.fqdn, dst.fqdn, data) for (src, dst, data) in edge_list)
js_files.append("dns_auth.js")
with open( dns_filename, 'w') as f_js:
f_js.write( js_template.render(
node_list = node_list,
edge_list = edge_list,