我学习了使用subprocess.call
修改mac地址的两种方法,第一种方法成功了但是第二种方法出错了,我不理解错误原因。这是我的代码:
#! /usr/bin/python3.5
import subprocess
interface = input("Enter Interface of Your Choice: ")
mac_chg = input("Enter New Mac Address: ")
print("[+]Changing Mac ADDRESS of " + interface + " to " + mac_chg)
subprocess.call(["ifconfig", interface, "down"])
subprocess.call(["ifconfig", interface, "hw", "ether", mac_chg])
subprocess.call(["ifconfig", interface, "up"])
这是错误信息:
Traceback (most recent call last):
File "/home/kali/PycharmProjects/hello/main.py", line 7, in <module>
subprocess.call(["ifconfig", interface, "down"])
File "/usr/lib/python3.8/subprocess.py", line 340, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ifconfig'
Process finished with exit code 1
因为这个错误,我无法继续进行。