-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrace_route.py
55 lines (47 loc) · 1.91 KB
/
trace_route.py
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
54
55
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from scapy.all import *
from scapy.layers.inet import traceroute
class TraceRoute(QWidget):
def __init__(self):
super().__init__()
self.hostn = QLabel("Enter Address/Hostname to trace:")
self.host = QLineEdit()
self.startTraceBtn = QPushButton()
self.startTraceBtn.setText('Trace Route')
self.startTraceBtn.clicked.connect(self.startTrace)
self.result = QTextEdit()
self.result.setReadOnly(True)
self.layoutTrace = QVBoxLayout(self)
self.layoutTrace.addWidget(self.hostn)
self.layoutTrace.addWidget(self.host)
self.layoutTrace.addWidget(self.startTraceBtn)
self.layoutTrace.addWidget(self.result)
self.setLayout(self.layoutTrace)
def startTrace(self):
if(len(self.host.text()) >= 1):
try:
result, unans = traceroute(
target=self.host.text(), dport=80, verbose=0, timeout=3)
output = []
output.append("\tRoute path\t\tResponse time")
result = sorted(result, key=lambda x: x[0].ttl)
prev_rcv_src = ''
for snd, rcv in result:
if prev_rcv_src == rcv.src:
break
output.append(
str("{}\t{}\t\t{} ms".format(
snd.ttl,
rcv.src,
(int((rcv.time - snd.sent_time)*1000))
)))
prev_rcv_src = rcv.src
output.append("\nUnanswered packets: {}".format(
len(unans)
))
self.result.setText('\n'.join(output))
except socket.gaierror:
self.result.setText(
"Invalid address/Could not get address info")