0
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.

skysoft999
  • 540
  • 1
  • 6
  • 27

1 Answers1

1

If by MAC id you mean MAC address, then you could use netifaces : Getting MAC Address

I recommend you read https://pypi.python.org/pypi/netifaces

Anes Belfodil
  • 11
  • 2
  • 2