Skip to content

Commit

Permalink
more refactor and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberRoute committed Sep 28, 2024
1 parent 88eabe1 commit cc92a2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
15 changes: 1 addition & 14 deletions core/arp_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
32 changes: 21 additions & 11 deletions core/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cc92a2e

Please sign in to comment.