Проблема с подключением к сети в питоне
Пишу код для смены MAC-адреса, при подключении к проводной сети код работает без ошибок, при подключении к беспроводной ошибка:
ERROR - Failed to re-enable the network interface: Command 'netsh interface set interface "IDK" admin=enable' returned non-zero exit status 1.
Причем постоянно.
def change_mac_address(interface, new_mac):
try:
# Disable the network interface
subprocess.check_call(f'netsh interface set interface "{interface}" admin=disable', shell=True)
key = r'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0001'
# Change the MAC address in the registry
subprocess.check_call(f'reg add "{key}" /v NetworkAddress /d {new_mac} /f', shell=True)
# Enable the network interface
subprocess.check_call(f'netsh interface set interface "{interface}" admin=enable', shell=True)
except subprocess.CalledProcessError as e:
logging.error(f"Failed to change MAC address: {e}")
sys.exit(1)
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")
sys.exit(1)
finally:
# Attempt to re-enable the interface even if the operation fails
try:
subprocess.check_call(f'netsh interface set interface "{interface}" admin=enable', shell=True)
except Exception as e:
logging.error(f"Failed to re-enable the network interface: {e}")
вот кусочек кода, из-за которого идет ошибка