中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

python 獲取mac地址的兩種方法

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
1)通用方法,借助uuid模塊
def get_mac_address():
  import uuid
      node = uuid.getnode()
      mac = uuid.UUID(int = node).hex[-12:]
  return mac

(2)按照操作系統(tǒng)平臺(tái)來(lái)

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

需要提醒的是,方法一,也就是通過(guò)uuid來(lái)實(shí)現(xiàn)的方法適用性更強(qiáng)一些,因?yàn)橥ㄟ^(guò)解析popen的數(shù)據(jù)還受到系統(tǒng)語(yǔ)言環(huán)境的影響,比如在中文環(huán)境 下"ipconfig/all"的結(jié)果就包含有中文,要查找mac地址的話就不能查找Physical Address;而應(yīng)該是“物理地址”

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:發(fā)送email 帶附件的Python代碼

下一篇:python循環(huán)監(jiān)控遠(yuǎn)程端口的代碼