我目前正在编写一个MAC转换器脚本,我遇到了一个错误



这是我的代码:

import subprocess

import optparse
parser = optparse.OptionParser()
parser.add_option("-i", "--interface", dest="interface", help="interface to change MAC adress")
parser.add_option("-m", "--mac", dest="mac", help="new mac adress")
(options, arguments) = parser.parse_args()
interface = options.interface
mac = options.mac 
#print("(+) Your mac adress for " + interface + " has been changed to " + mac)
subprocess.call(["sudo ifconfig",interface, "down"])
subprocess.call(["sudo ifconfig",interface, "hw", "ether", mac])
subprocess.call(["sudo ifconfig",interface, "up"])

这就是错误:

Traceback (most recent call last):
File "mac_changer.py", line 10, in <module>
subprocess.call(["sudo 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 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1639, in _execute_child
self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not NoneType

我使用的是Ubuntu 20.04。

看起来您没有为interface赋值,因此它是NoneType。请确保使用-i调用脚本并指定网络接口。

最新更新