gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)
Write a Python code that displays the list of all devices that are connected to my…
- User
Write a Python code that displays the list of all devices that are connected to my internet network.
- Assistant
To display the list of all devices connected to your internet network, you can use the
scapylibrary in Python. Here's an example code snippet that can help you achieve this:from scapy.all import srp, Ether, ARP def get_connected_devices(ip_range): # Create an ARP request packet to get the list of connected devices arp_request = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip_range) # Send the ARD request packet and capture the response result = srp(arp_request, timeout=3, verbose=0)[0] # Parse the response and collect the IP and MAC addresses of connected devices devices = [] for sent, received in result: devices.append({'ip': received.psrc, 'mac': received.hwsrc}) return devices # Specify the IP range or subnet of your network (e.g., '192.168.1.0/24') ip_range = 'your_ip_range_here' # Get the list of connected devices connected_devices = get_connected_devices(ip_range) # Display the list of connected devices along with their IP and MAC addresses print("Connected Devices:") print("------------------") for device in connected_devices: print(f"IP: {device['ip']}\t MAC: {device['mac']}")Make sure you have
scapylibrary installed before running the code. You can install it usingpip install scapy. Replace'your_ip_range_here'in theip_rangevariable with the appropriate IP range or subnet of your network.