Need IP+hostname in tracroute

i have below pyton3 code from Github and works for me . but i would need Hostname+IP address during traceroute

import ipaddress
import socket
from scapy.layers.inet import traceroute
import tkinter as tk
import networkx as nx
import matplotlib
import matplotlib.pyplot as plt

class Application(tk.Frame):
def __init__(self, master=None):

def create_form(self):
self.formFrame = tk.Frame(self)
self.IPLabel = tk.Label(self.formFrame, text=‘IP’)
self.IPLabel.grid(row=0, column=0)
self.IPEntry = tk.Entry(self.formFrame)
self.IPEntry.grid(row=0, column=1)
self.MaskLabel = tk.Label(self.formFrame, text=‘Mask’)
self.MaskLabel.grid(row=0, column=2)
self.MaskEntry = tk.Entry(self.formFrame)
self.MaskEntry.grid(row=0, column=3)
self.topologyButtonText = tk.StringVar()
self.topologyButtonText.set(‘Show topology’)
self.topologyButton = tk.Button(self, textvariable=self.topologyButtonText, command=self.get_topology)

def cleanup_figure(self):
if hasattr(self, ‘fig’):
self.fig = plt.figure(figsize=(8, 6), dpi=100)

def get_topology(self):

def generate_figure(self):
edges = self.trace_route()
network_graph = nx.Graph()
node_size = [float(*50 for v in network_graph]
node_color = [1-1/(1+float( for v in network_graph]
nx.draw(network_graph, node_size=node_size, node_color=node_color, width=0.5, with_labels=True)

def trace_route(self):
edges = set()
network = list(ipaddress.IPv4Network(self.IPEntry.get() + ‘/’ + self.MaskEntry.get()))

res, _ = traceroute(list(map(lambda x: str(x), network)))
if not hasattr(self, ‘res’):
self.res = res
self.res = self.res + res

tr_dict = dict()
help_dict = dict()

for r in self.res:
if r[0].dst in tr_dict:
if r[1].src in help_dict[r[0].dst]:
tr_dict[r[0].dst][r[0].ttl] = r[1].src
tr_dict[r[0].dst] = {r[0].ttl: r[1].src}
help_dict[r[0].dst] = {r[1].src}

for ttl_dict in tr_dict.values():
for ttl in sorted(ttl_dict.keys()):
edges.add((last_src, ttl_dict[ttl]))

except Exception as e:
edges.add((‘localhost’, ‘localhost’))

return edges

if __name__ == ‘__main__’:
app = Application(master=tk.Tk())
app.master.title(‘Network Topology Viewer’)

Please let me know what further we need to add …
Thanks in advance 

You don’t show us what the input is, nor do you show the resulting output. It is difficult to guess what needs to be solved.  You also did not put the python into a code block, so all the (very necessary!) formatting has been lost. For future reference, pointing us to a gist or pointer to a github repo would be far more useful.

You’re using scapy, so a google for “scapy traceroute” finds a few hits which might be informative. The ip addresses are all there.

Once you have an ip address, you need to perform a DNS lookup to get its hostname.

I’ll let you do the google “scapy dns lookup” yourself, the first few hits look useful.

Hi @shamim11287 ,

This post was moved to a different board that fits your topic of discussion a bit better.  This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the Programming Help and Discussion board.

Let me know if you have any other questions or if I can help with anything else.


This saved as CSS or py?