Get mac addresses:
ifconfig -a | grep HWaddr | tr -s " " | cut -d' ' -f5
Output:
b8:27:eb:34:53:7e //eth0
b8:27:eb:61:06:2b //wlan0
Get serial number:
awk '/Serial/{print $3}' /proc/cpuinfo
Output:
000000002b34537e
Notice that the last 6 characters of the serial number and the last 6 characters of the eth0 mac address are the same.
def getserial():
# Extract serial from cpuinfo file
cpuserial = "0000000000000000"
try:
f = open('/proc/cpuinfo','r')
for line in f:
if line[0:6] == 'Serial':
cpuserial = line[10:26]
f.close()
except:
cpuserial = "ERROR000000000"
return cpuserial
def getMAC(interface):
# Return the MAC address of interface
try:
str = open('/sys/class/net/' + interface + '/address').read()
except:
str = "00:00:00:00:00:00"
return str[0:17]