查找Python3的Mac地址

时间:2017-12-12 12:12:13

标签: python python-3.x mac-address

我通过运行此python脚本来获取错误消息以获取Mac地址。这对于python 2.7非常好,但是对于python 3.6its抛出错误。

import subprocess, re
listOutputMAC = 0
def mac_list():
    output = subprocess.check_output("getmac")
    print(output)
    regex = r"([0-9A-F]{2}[:-]){5}([0-9A-F]{2})"
    matches = re.finditer(regex, output)

    listOutputMAC = []
    for matchNum, match in enumerate(matches):
        matchNum = matchNum + 1
        listOutputMAC.append("{match}".format(matchNum=matchNum, start=match.start(),
                                              end=match.end(), match=match.group()))
    print(output)
    return listOutputMAC

var1 = mac_list()
print(var1)

这是我的错误日志: 回溯(最近一次调用最后一次):

  File "s.py", line 19, in <module>
    var1 = mac_list()
  File "s.py", line 9, in mac_list
    matches = re.finditer(regex, output)
  File "C:\Users\Cookie1\Anaconda3\envs\py3\lib\re.py", line 229, in finditer
    return _compile(pattern, flags).finditer(string)
TypeError: cannot use a string pattern on a bytes-like object

0 个答案:

没有答案