diff --git a/core/arp_scanner.py b/core/arp_scanner.py index a636d84..37348a4 100644 --- a/core/arp_scanner.py +++ b/core/arp_scanner.py @@ -199,19 +199,6 @@ def quit_application(self): self.arp_scanner_thread.wait() QTimer.singleShot(2000, self.close) -class ARPScanner: - """Arp Scanner""" - - @staticmethod - def get_hostname(ip_address): - "get hostname" - try: - hostname = socket.gethostbyaddr(ip_address)[0] - return hostname - except socket.herror: - return "N/A" - except socket.gaierror: - return "N/A" class ARPScannerThread(QThread): # pylint: disable=too-few-public-methods """Executing arp scan in separate thread""" @@ -259,6 +246,6 @@ def run(self): ip_address = packet[1][ARP].psrc mac = packet[1][ARP].hwsrc device_vendor = self.mac_vendor_lookup.lookup_vendor(mac) - hostname = ARPScanner.get_hostname(ip_address) + hostname = net.get_hostname(ip_address) arp_results.append((ip_address, mac, hostname, device_vendor, packet[1][ARP])) self.finished.emit(arp_results) diff --git a/core/networking.py b/core/networking.py index 9d1d789..d97a911 100644 --- a/core/networking.py +++ b/core/networking.py @@ -60,20 +60,30 @@ def get_ip_address(): print(f"Error while getting IP address: {e}") return None +def get_hostname(ip_address): + "get hostname" + try: + hostname = socket.gethostbyaddr(ip_address)[0] + return hostname + except socket.herror: + return "N/A" + except socket.gaierror: + return "N/A" + def calculate_network_cidr(ip_address, subnet_mask): - """calculate network cidr""" - # Split the IP address and subnet mask into octets - ip_octets = [int(octet) for octet in ip_address.split('.')] - subnet_octets = [int(octet) for octet in subnet_mask.split('.')] + """calculate network cidr""" + # Split the IP address and subnet mask into octets + ip_octets = [int(octet) for octet in ip_address.split('.')] + subnet_octets = [int(octet) for octet in subnet_mask.split('.')] - # Perform bitwise AND operation on corresponding octets - network_octets = [ip_octets[i] & subnet_octets[i] for i in range(4)] + # Perform bitwise AND operation on corresponding octets + network_octets = [ip_octets[i] & subnet_octets[i] for i in range(4)] - # Calculate the number of set bits in the subnet mask - prefix_length = sum(bin(octet).count('1') for octet in subnet_octets) + # Calculate the number of set bits in the subnet mask + prefix_length = sum(bin(octet).count('1') for octet in subnet_octets) - # Format the network address in CIDR notation - network_address = '.'.join(map(str, network_octets)) + '/' + str(prefix_length) + # Format the network address in CIDR notation + network_address = '.'.join(map(str, network_octets)) + '/' + str(prefix_length) - return network_address + return network_address