skysoft999
skysoft999

Reputation: 579

How to get Windows MacID using python script

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  

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

Upvotes: 0

Views: 78

Answers (1)

Anes Belfodil
Anes Belfodil

Reputation: 11

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

Upvotes: 1

Related Questions