Top.Mail.Ru
Ответы

Cannot use a string pattern on a bytes-like object Ошибка при програмирование на паитон

При програмиирование на паитон вылазит вот такая ошибка :
Traceback (most recent call last):
File "/root/PycharmProjects/hello/macc.py", line 33, in <module>
mac_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w:", ifconfig_result)
File "/usr/lib/python3.9/re.py", line 201, in search
return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object
Вот код программы:
#!/usr/bin/env python

import subprocess
import optparse
import re


def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i", "--interface", dest="interface", help="Интерфейс мак адреса")
parser.add_option("-m", "--mac", dest="new_mac", help="Новый мак адресс")
(options, arguments) = parser.parse_args()
if not options.interface:
parser.error("[-]Пожалуйста введите итерфейс мак адреса для справки --help")
elif not options.new_mac:
parser.error("[-]Пожалуйста введите мак адрес для справки --help")
return options


def change_mac(interface, new_mac):
print("[+] Меняем мак адрес интерфеиса под названием " + interface + " на " + new_mac)
subprocess.call(["ifconfig", interface, "down"])
subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
subprocess.call(["ifconfig", interface, "up"])


options = get_arguments()
#change_mac(options.interface, options.new_mac)

ifconfig_result = subprocess.check_output(["ifconfig", options.interface])
print(ifconfig_result)

mac_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w:", ifconfig_result)
print(mac_result.group(0))

По дате
По рейтингу
Аватар пользователя
Просветленный

ifconfig_result = subprocess.check_output(["ifconfig", options.interface]).decode()
в следующий раз прикрепляй стектрейс