我的get_current_mac函数:
def get_current_mac(interface):
ifconfig_result = subprocess.check_output(["ifconfig",interface])
mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",ifconfig_result)
if mac_address_search_result:
return mac_address_search_result.group(0)
else:
print("[-] Could not read MAC address.")
然后我想将结果打印到屏幕上
options = get_arguments()
current_mac = get_current_mac(options.interface)
print("Current MAC address is: " + str(current_mac))
整个错误是:
Traceback (most recent call last):
File "./MAC_changer.py",line 38,in <module>
current_mac = get_current_mac(options.interface)
File "./MAC_changer.py",line 30,in get_current_mac
mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",ifconfig_result)
File "/usr/lib/python3.7/re.py",line 183,in search
return _compile(pattern,flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object
第38行是:options = get_arguments()
第30行是:mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",ifconfig_result)