python-3.x - 可能的 if/elif 语句错误
问题描述
好的,伙计们,我发誓我并不愚蠢,但是我在编写后门服务器/客户端脚本时遇到了最奇怪的事情。
这是一个示例/简化脚本,它完全按照我的预期工作:
command = input(str("Command >>>"))
if command == '1':
print("1")
elif command == '2':
print("2")
elif command == '3':
print("3")
elif command == '4':
print("4")
else:
print("Not a command")
很简单,对吧?现在通常我只使用一个示例脚本,但我即将把头撞到一张桌子上,所以这里是真实脚本的一部分:
while 1:
print("")
command = input(str("Command >> "))
if command == "view_cwd":
conn.send(command.encode())
print("")
print("Command sent, waiting for execution... ")
print("")
files = conn.recv(5000)
files = files.decode()
print("Command Output: ", files)
elif command == "quit":
quit()
elif command == "download_file":
conn.send(command.encode())
filepath = input(str("Please enter filename and path: "))
conn.send(filepath.encode())
file = conn.recv(100000)
filename = input(str(Enter preferred filename: ))
new_file = open(filename, 'wb')
new_file.write(file)new_file.close()
print(filename, "has been downloaded")
elif command == "custom_dir":
conn.send(command.encode())
print("")
user_input = input(str("Custom Dir: "))
conn.send(user_input.encode())
print("")
print("Command has been sent")
print("")
files = conn.recv(5000)
files = files.decode()
print("Custom DIR result: ", files)
else:
print("")
print("Command not recognized")
看起来还是很标准的吧?现在这是奇怪的部分:“view_cwd”、“quit”和“custom_dir”命令工作正常并执行,但如果我输入“download_file”,我会得到这个输出:
Command >> download_file
Command not recognized
Command >>
这是我制作的错误代码,但我完全看不出为什么其他 elif/if 语句有效,但不是这个。我错过了一些明显的东西吗?
解决方案
推荐阅读
- excel - VBA - 获取标签名称的 XPath 语法是什么
- javascript - React 文件查看器不适用于 Firebase 存储链接
- javascript - 在 n 单击时将 href 添加到锚标记
- python - 按组返回到最近点的距离 - python
- reactjs - 我可以在没有缓存策略的情况下使用 apollo 客户端的反应变量吗?
- sql - 将同一用户的结果合并为一个结果
- google-chrome - 是否有人在 Chrome 87.0.4280.88 中也收到此错误?
- oauth-2.0 - 如何使用 lua 从鬣蜥访问受 Oauth2 保护的 API
- javascript - OpenLayer Bing 地图导入错误 - Wordpress
- sharepoint - SPfx 连接到共享点上下文时出错