import sys
import os
mac = 0
def mac_list():
global mac
if sys.platform == 'win32':
for line in os.popen("ipconfig /all"):
if line.lstrip().startswith('Physical Address'):
mac = line.split(':')[1].strip().replace(':','-')
break
else:
for line in os.popen("/sbin/ifconfig"):
if line.find('Ether') > -1:
mac = line.split()[4]
break
return mac
- I got this code from StackOverflow only. This works really good as my requirement to get MAC ID of Windows machine.
-My Problem is When machine is connected to both Wlan and Ethernet this code fetching both activated MACids. I want to get only one active MAC(preferaly ethernet 1st and then if it's not available then wlan) can anyone recommend proper condition to filter the appropriate mac.