首页 > 编程语言 > 详细

python获取mac地址的方法

时间:2019-06-03 17:50:00      阅读:209      评论:0      收藏:0      [点我收藏+]

方法一:

  借助uuid模块

  def get_mac_address():
  import uuid
      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

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

python获取mac地址的方法

原文:https://www.cnblogs.com/jubing/p/10968592.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!