python获取mac地址的方法

方法一:

  借助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

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

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

时间: 2024-08-02 04:32:52

python获取mac地址的方法的相关文章

用python获取MAC地址和IP地址

# ifconfig eth0 eth0      Link encap:Ethernet  HWaddr 50:E5:49:3A:EA:90             inet addr:172.28.10.71  Bcast:172.28.10.255  Mask:255.255.255.0           inet6 addr: fe80::52e5:49ff:fe3a:ea90/64 Scope:Link           UP BROADCAST RUNNING MULTICAST

C# 获取mac地址 本机或者 远程的

/// 获取本机网卡mac地址代码 /// </summary> /// <returns></returns> /// /// <summary> public string GetNetworkAdpaterID() { try { string mac = ""; System.Management.ManagementClass mc = new System.Management.ManagementClass("Wi

Python windows下获取MAC地址的一种方法

我最近有一个项目,使用Python在win32下开发一个COM组建,该COM组建其中一个方法是获取本地电脑的MAC地址. 需求很简单,虽然我是Python新手中的新手,但我还是会使用搜索引擎进行搜索. 百度一下,发现大部分都介绍使用import UUID获取MAC地址,或使用os.popen("ipconfig /all")的方式获取.而后者容易受到操作系统中英文环境影响. 如这篇文章:http://www.cnblogs.com/Jerryshome/archive/2011/11/

java获取本机IP地址和MAC地址的方法

// 获取ip地址 public static String getIpAddress() { try { Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces(); InetAddress ip = null; while (allNetInterfaces.hasMoreElements()) { NetworkInterface netInterface = (Netw

C#获取MAC地址的几种方法

首先需要用到的一些方法和类: public enum NCBCONST { NCBNAMSZ = 16, MAX_LANA = 254, NCBENUM = 0x37, NRC_GOODRET = 0x00, NCBRESET = 0x32, NCBASTAT = 0x33, NUM_NAMEBUF = 30, } [StructLayout(LayoutKind.Sequential)] public struct ADAPTER_STATUS { [MarshalAs(UnmanagedTy

【转载】获取MAC地址方法大全

From:http://blog.csdn.net/han2814675/article/details/6223617 Windows平台下用C++代码取得机器的MAC地址并不是一件简单直接的事情.到目前为止,作者尚未发现有任何一个通用的100%的适用于所有Windows平台的方法可以稳定的取得MAC地址.而有些应用(比如MMORPG)则需要稳定的得到机器的MAC地址,解决方案往往是通过多种方法依次使用来提高成功率. 说明: 以下方法只会返回多网卡的第一个MAC地址. 网上有很多文章和源码来解

Android 获取WIFI MAC地址的方法

1. 经常用法,调用Android的API:WifiManager <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo

Android 获取MAC地址最靠谱的方法。

众所周知在安卓开发中,我们经常使用WifiManager获取MAC地址做设备映射,但会出现这样那样的问题,比如说开了WIFI获取不到地址了.不开WIFI获取不到地址了.刚开机获取不到地址了.网卡未启动获取不到地址了.综上所述最靠谱的方法还是直接用busybox读取系统文件中的MAC地址比较稳妥.    public String getMacAddress() {         String result = "";         String Mac = ""

用派克斯出现651 查看&修改mac地址的方法

1.winxp查看mac地址的方法 2.winxp修改mac地址的方法 电脑MAC地址是网卡适配器在出厂时就已经被固定了的,也叫物理地址,每块网卡适配器有全球唯一的MAC地址,一般情况是不需要修改MAC地址的,但有些特殊情况需要更改MAC地址来实现一些特殊的要求,修改之前大家先知道如何查看 第一种方法 1.在开始菜单栏选择"运行" 2.在运行中输入"cmd" 3.我们会看到有一个黑色窗口弹出,在里边输入"ipconfig /all"然后按回车键