mirror of
https://github.com/20kaushik02/AUNMS---Network-Monitoring-System.git
synced 2025-12-06 08:04:06 +00:00
Bit of formatting, ping, and one typo
This commit is contained in:
parent
3cc3aa40f8
commit
e1ef9be2d9
@ -76,7 +76,9 @@ class NetworkMonitor(QMainWindow):
|
||||
if self.interfaceSelected == None:
|
||||
self.interfaceDialog()
|
||||
|
||||
print(f"Monitoring - {self.interfaceSelected}")
|
||||
print("Monitoring - {}".format(
|
||||
self.interfaceSelected
|
||||
))
|
||||
|
||||
self.actionStart.setEnabled(False)
|
||||
self.actionStop.setEnabled(True)
|
||||
@ -139,10 +141,12 @@ class NetworkMonitor(QMainWindow):
|
||||
self.setColortoRow(self.tableWidget, rowpos, QColor(173,191, 255))
|
||||
elif(tableData['Protocol'] == 'UDP'):
|
||||
self.setColortoRow(self.tableWidget, rowpos, QColor(157,240,255))
|
||||
elif(tableData['Protocol'] == 'Other'):
|
||||
self.setColortoRow(self.tableWidget, rowpos, QColor(125,125,146))
|
||||
elif(tableData['Protocol'] == 'ARP'):
|
||||
self.setColortoRow(self.tableWidget, rowpos, QColor(157,240,77))
|
||||
elif(tableData['Protocol'] == 'ICMP'):
|
||||
self.setColortoRow(self.tableWidget, rowpos, QColor(255, 182, 193))
|
||||
elif(tableData['Protocol'] == 'Other'):
|
||||
self.setColortoRow(self.tableWidget, rowpos, QColor(125,125,146))
|
||||
|
||||
|
||||
def setColortoRow(self, table, rowIndex, color):
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import sys
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtWidgets import *
|
||||
@ -32,8 +31,8 @@ class NetworkMonitorThread(QObject):
|
||||
counter = 0
|
||||
while True:
|
||||
layer = packet.getlayer(counter)
|
||||
if layer != None:
|
||||
if layer.name != "Padding":
|
||||
if layer is not None:
|
||||
if layer.name is not "Padding":
|
||||
layers.append(layer.name)
|
||||
else:
|
||||
break
|
||||
@ -102,7 +101,13 @@ class NetworkMonitorThread(QObject):
|
||||
packet[TCP].ack,
|
||||
packet[TCP].window
|
||||
)
|
||||
|
||||
elif ICMP in packet:
|
||||
protocol = "ICMP"
|
||||
info = "type={} code={} chksum={}".format(
|
||||
packet[ICMP].type,
|
||||
packet[ICMP].code,
|
||||
packet[ICMP].chksum,
|
||||
)
|
||||
elif ARP in packet:
|
||||
protocol = "ARP"
|
||||
info = "hwtype={} ptype={} hwlen={} plen={} op={}".format(
|
||||
@ -121,5 +126,5 @@ class NetworkMonitorThread(QObject):
|
||||
count=0,
|
||||
iface=self.interface,
|
||||
prn=self.handlePacket,
|
||||
stop_filter={lambda x: self.sniffStatus()}
|
||||
stop_filter=lambda x: self.sniffStatus()
|
||||
)
|
||||
|
||||
29
ping.py
29
ping.py
@ -1,10 +1,8 @@
|
||||
import sys
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from scapy.all import *
|
||||
from scapy.layers.inet import IP
|
||||
from scapy.layers.inet import ICMP
|
||||
from scapy.layers.inet import IP, ICMP, icmpcodes, icmptypes
|
||||
|
||||
|
||||
class Ping(QWidget):
|
||||
@ -31,10 +29,29 @@ class Ping(QWidget):
|
||||
def startPing(self):
|
||||
if(len(self.host.text()) >= 1):
|
||||
try:
|
||||
packet = IP(dst=self.host.text(), ttl=10)/ICMP()
|
||||
packet = IP(dst=self.host.text())/ICMP()
|
||||
output = sr1(packet, timeout=2)
|
||||
if output is not None:
|
||||
self.result.setText(output.summary())
|
||||
except socket.gaierror as e:
|
||||
res_type = icmptypes[output.type]
|
||||
res_code = ""
|
||||
if output.type in icmpcodes:
|
||||
res_code = " - "+icmpcodes[output.type][output.code]
|
||||
ping_time = int((output.time - packet.sent_time)*1000)
|
||||
|
||||
self.result.setText(
|
||||
"Ping results:\nSummary: {}\n\nType:\t\t{}{}\nTime:\t\t{}ms\nSource:\t\t{}\nDestination:\t{}\
|
||||
\nTTL:\t\t{}".format(
|
||||
output.summary(),
|
||||
res_type,
|
||||
res_code,
|
||||
ping_time,
|
||||
packet[IP].src,
|
||||
packet[IP].dst,
|
||||
packet[IP].ttl
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.result.setText("Request timed out.")
|
||||
except socket.gaierror:
|
||||
self.result.setText(
|
||||
"Invalid address/Could not get address info")
|
||||
|
||||
@ -32,12 +32,20 @@ class TraceRoute(QWidget):
|
||||
result, unans = traceroute(
|
||||
target=self.host.text(), dport=80, verbose=0)
|
||||
output = []
|
||||
output.append("\tRoute path\tResponse time")
|
||||
output.append("\tRoute path\t\tResponse time")
|
||||
result = sorted(result, key=lambda x: x[0].ttl)
|
||||
|
||||
for snd, rcv in result:
|
||||
output.append(
|
||||
str(f"{snd.ttl}\t{rcv.src}\t\t{(int((rcv.time - snd.sent_time)*1000))} ms"))
|
||||
output.append(f"\nUnanswered packets: {len(unans)}")
|
||||
str("{}\t{}\t\t{} ms".format(
|
||||
snd.ttl,
|
||||
rcv.src,
|
||||
(int((rcv.time - snd.sent_time)*1000))
|
||||
)))
|
||||
output.append("\nUnanswered packets: {}".format(
|
||||
len(unans)
|
||||
))
|
||||
self.result.setText('\n'.join(output))
|
||||
except socket.gaierror as e:
|
||||
except socket.gaierror:
|
||||
self.result.setText(
|
||||
"Invalid address/Could not get address info")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user