【发布时间】:2020-02-11 04:38:05
【问题描述】:
我正在为 linux 编写一个查看 mac 地址的简单程序。我的程序应该查看“ifconfig”并使用正则表达式仅提取 MAC 地址。
import subprocess
import re
print('This program will only look at the mac address.')
print('Enter your interface.(for example: wlan0))')
interface = input(': ')
find_mac = subprocess.check_output(["ifconfig", interface], shell=True)
mac_clean = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w\:\w\w", find_mac)
print(mac_clean.group(0))`
我希望的输出是MY:MAC:ADDRESS,但实际输出是
mac_clean = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", find_mac)
搜索中的文件“/usr/lib/python3.7/re.py”,第 183 行
return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes - like object
【问题讨论】:
标签: python