文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>python(5) 读取mac地址

python(5) 读取mac地址

时间:2009-03-14  来源:alexnetwork

#!/usr/bin/python
import os
import re
CmdLine = 'arp -n'
r = os.popen(CmdLine).read()
L = re.findall('10.26.12.1.*?([0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2})', r)
ret = L[0]
print ret

*****************************

import os
import re

def GetMac():
#Windows下的
    if os.name == 'nt':
        try:
            ret = ''
            CmdLine = 'ipconfig /all'
            r = os.popen(CmdLine).read()
            if r:
                L = re.findall('Physical Address.*?([0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2})', r)
                if len(L) > 0:
                    ret = L[0]
        except:
            pass
       
#Linux/Unix下
    elif os.name == "posix":
        try:
            ret = ''
            CmdLine = 'ifconfig'
            r = os.popen(CmdLine).read()
            if r:
                L = re.findall('HWaddr.*?([0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2})', r)
                if len(L) > 0:
                    ret = L[0]
        except:
            pass
    else:
        pass
    return ret

if __name__ == '__main__':
    mac =  GetMac()
    print mac
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载