
The output will be a string containing the ARP table, and the MAC address will be the fourth item in the list of words obtained by splitting the output string on whitespace. This code will call the arp command with the -n flag, which displays the ARP table with IP addresses and MAC addresses, and the IP address of the device you want to get the MAC address for. Output = subprocess.check_output(arp_command).decode() Here is an example of how to do this: import subprocess

To use the arp command to get the MAC address of a device in Python, you can use the subprocess module to call the arp command and capture the output. Get MAC address of a different device in Python If you want to get the MAC address of a different device on the same network, you will need to use a different method such as using the arp command or sending a network packet to the device and reading the MAC address from the response. Keep in mind that this method only works for the device running the Python script. If you want to print it in the traditional MAC address format (e.g., 00:11:22:33:44:55), you can use the hex function to convert the integer to a hexadecimal string, and then use string formatting to insert the colons: import uuid The getnode function returns the MAC address as an integer. This function generates a unique MAC address based on the system’s hardware information. To get the MAC address of a device in Python, you can use the getnode function in the uuid module. This module is particularly used to fetch the MAC address of any system. A media access control address is a distinctive identifier of a system that helps two or more devices connect, especially when on the same local network.


If (ipAddress.AddressFamily = .InterNetwork)ĪrpErrorCodes c = (ArpErrorCodes)SendARP((uint)ipAddress.In this tutorial, we will write a Python program using a special module called UUID to fetch your system’s MAC address. Static PhysicalAddress LocateMacAddress(IPAddress ipAddress) PhysicalAddress pa = LocateMacAddress(IPAddress.Parse("172.16.0.99")) I am assuming that you have the IP address of the network printer and your pc and the printer are at the same local network.
