xxxxxxxxxx
ip addr show $(awk 'NR==3{print $1}' /proc/net/wireless | tr -d :) | awk '/ether/{print $2}'
xxxxxxxxxx
import fcntl
import socket
import struct
def get_mac_address(interface='eth0'):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
iface = struct.pack('256s', interface.encode('utf-8'))
mac_address = fcntl.ioctl(sock.fileno(), 0x8927, iface)[18:24]
mac_address = ':'.join(['{:02x}'.format(byte) for byte in mac_address])
return mac_address
except IOError:
return "Could not get MAC address"
# Usage
mac_address = get_mac_address()
print(mac_address)