Created
April 14, 2023 05:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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