Práctica Final

#!/usr/local/bin/python
#-*- coding:utf-8 -*-

#region imports
import logging
logging.getLogger(name="scapy.runtime").setLevel(level=logging.ERROR)
import warnings
from cryptography.utils import CryptographyDeprecationWarning
warnings.filterwarnings("ignore", category=CryptographyDeprecationWarning)
import scapy.all as scapy # type: ignore

#endregion

def scan(target: str) -> str:
	"""
	Scan the network to get the IP and MAC address of the devices connected to the network.
	PARAMETERS:
	----------
		target: str -> The IP address of the network to scan.
	RETURNS:
	--------
		str -> The IP and MAC address of the devices connected to the network.
	EXAMPLE:
	--------
		>>> scan("10.20.20.1/24")
	"""
	arp_request: scapy.layers.l2.ARP = scapy.ARP(pdst=target)
	broadcast: scapy.layers.l2.Ether = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
	arp_request_broadcast: scapy.layers.l2.Ether = broadcast/arp_request
	answered_list: scapy.plist.SndRcvList
	answered_list, _ = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)
	clients: str = f"IP\\t\\t\\tMAC Address\\n{'-'*41}\\n"
	for element in answered_list:
		clients += f"{element[1].psrc}\\t\\t{':'.join(element[1].hwsrc.split(':')[:2])}\\n"  # f"{element[1].psrc}\\t\\t{element[1].hwsrc}\\n"
	return clients

def main() -> None:
	"""
	Main function to execute the ARP scanner.
	"""
	target: str = "192.168.1.0/24"
	print(scan(target=target))

if __name__ == '__main__':
	main()

Python-Workshop-101/clase-4 at main · Zeta-0x00/Python-Workshop-101