方法一:

  借助uuid模块

import uuid

def get_mac_address():

  node = uuid.getnode()

  mac = uuid.UUID(int = node).hex[-12:]
  return mac

方法二:

  按操作系统平台来:

def get_mac_address():
    '''
    @summary: return the MAC address of the computer
    '''
    import sys
    import os
    mac = None
    if sys.platform == "win32":
        for line in os.popen("ipconfig /all"):
            print line
            if line.lstrip().startswith("Physical Address"):
                mac = line.split(":")[1].strip().replace("-", ":")
                break
    else:
        for line in os.popen("/sbin/ifconfig"):
            if 'Ether' in line:
                mac = line.split()[4]
                break
    return mac

个人推荐方法一,简单通用