用菜单编写基本的ping程序。每次运行代码时,它都会循环我写的菜单,而我不确定为什么。谢谢
这是我写的代码:
import nmap
def menu():
print (30 * "-", "I hate the CIA", 30 * "-")
print ("1. Ping")
print ("2. ???")
print ("3. ???")
menu()
choice = input("Enter your choice [1 - 3]: ")
if choice==1:
input("Please choose your target: ")
t = nmap.PortScanner()
t.scan(hosts=input, arguments='-sP')
我知道这可能很混乱,并且像我所做的那样,用“待办事项”写作可能是不好的习惯有更好的方法。也许答案对我来说很清楚,也许不是。帮助您表示赞赏。谢谢大家3
Here is the code I wrote:
import nmap
def menu():
print (30 * "-", "I hate the CIA", 30 * "-")
print ("1. Ping")
print ("2. ???")
print ("3. ???")
menu()
choice = input("Enter your choice [1 - 3]: ")
if choice==1:
input("Please choose your target: ")
t = nmap.PortScanner()
t.scan(hosts=input, arguments='-sP')
I know it's probably very messy and it's likely bad practice to write in "to-be functionalities" like I have done, but I'm pretty new to this and I'm willing to take it out if there is a better way. Perhaps the answer is clear to me, maybe not. Help is appreciated. Thanks all <3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输入()始终返回字符串。
尝试:
或者,如果您需要“选择”的数值值,则可以将输入字符串转换为整数:
但是如果用户键入非数字值,这将失败。
input() always return a string.
Try:
Alternatively if you want numerical values for 'choice', you can convert input string to integer:
But this will fail if user types non-numerical value.