Skip to content

Instantly share code, notes, and snippets.

@lakpa-tamang9
Created April 14, 2023 05:30
Show Gist options
  • Save lakpa-tamang9/c7b67d038ab3c4d64e79b1483f92a55d to your computer and use it in GitHub Desktop.
Save lakpa-tamang9/c7b67d038ab3c4d64e79b1483f92a55d to your computer and use it in GitHub Desktop.
Getting the IP and MAC address of the current devices connected to the same network
import os
import re
# os.system('arp -a')
outputs = os.popen('arp -a').read().split('\n')
addresses = []
for output in outputs:
if output != '':
ip = output.split(" ")[1]
ip = re.sub(r'\(|\)', '', ip)
if not output.split(" ")[3] == "(incomplete)":
mac = output.split(" ")[3]
addresses.append((ip, mac))
print(addresses)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment