【发布时间】:2019-01-11 09:48:50
【问题描述】:
我正在开发一个程序,它会在 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"])
这是我得到的错误:
TypeError: must be str, not NoneType
此错误与我的打印行有关。我已经尝试过:print("[+] Changing MAC address for " + str(interface) + " to " + str(new_mac))
但这没有用。
当我这样做时,我收到了这个错误:
TypeError: expected str, bytes or os.Pathlike object, Not NoneType
在整个代码中将optparse 更改为argparse,并没有解决问题。
我没有给出任何命令行参数,因为我希望用户能够自己给它们。
希望你能帮助我。谢谢。
【问题讨论】:
-
请把完整的代码和问题本身的错误贴出来
-
请在问题中包含您的代码和错误,而不是图像,而不是链接。
-
粘贴您的代码。突出显示它。按 Ctrl+K。
-
你的程序需要命令行参数(接口和mac地址)。你没有通过。
-
另外,optparse 已经过时了。你应该使用argparse。