问题
i started learning ethical hacking from a udemy course.We were Taught how to change mac address by 2 methods of subprocess.call while the first one was successfull but the second method is giving me error and i am unable to understand it this is my code
#! /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"])
this is the error
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
i am unable to progress because of this error thankyou in advance
回答1:
In linux by default the subprocess.call doesn't use a shell to run our commands so you cant use the shell commands like cd.
so just add one more parameter to subprocess.call i.e shell= True and then try to execute.
For ex:
subprocess.call(["ifconfig", interface, "down"], shell=True).
来源:https://stackoverflow.com/questions/63805710/filenotfounderror-errno-2-no-such-file-or-directory-ifconfig