我在做一个程序,它可以改变你在python中的MAC地址。我真的在努力克服这个错误。这是我目前为止的代码:
import subprocess
import optparse
parser = optparse.OptionParser()
parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC adress")
parser.add_option("-m", "--mac", dest="new_mac", help="New MAC adress")
(options, arguments) = parser.parse_args()
interface = options.interface
new_mac = options.new_mac
print("[+] Changing MAC adress for " + interface + " to " + new_mac)
subprocess.call(["ifconfig", interface, "down"])
subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
subprocess.call(["ifconfig", interface, "up"])
这是我得到的错误:
这个错误是指我的打印线。我已经试过了:print("[+] Changing MAC address for " + str(interface) + " to " + str(new_mac))
,但是没有用。
当我这么做的时候,我得到了一个错误:
TypeError: expected str, bytes or os.Pathlike object, Not NoneType
在整个代码中将optparse
更改为argparse
,并没有解决问题。
我没有给出任何命令行参数,因为我希望用户能够自己给出它们。在
希望你能帮助我。谢谢。在
结果发现我的代码完全没问题。在运行代码之前,我必须先在终端中传递一些命令行。相反,我想运行代码,然后传递参数。在
相关问题 更多 >
编程相关推荐