用菜单编写基本的ping程序。每次运行代码时,它都会循环我写的菜单,而我不确定为什么。谢谢

发布于 2025-01-31 21:32:04 字数 436 浏览 3 评论 0原文

这是我写的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鼻尖触碰 2025-02-07 21:32:04

输入()始终返回字符串。

尝试:

...
if choice == '1':
   input("Please choose your target: ")
   ...

或者,如果您需要“选择”的数值值,则可以将输入字符串转换为整数:

choice = int(input("Enter your choice [1 - 3]: "))

但是如果用户键入非数字值,这将失败。

input() always return a string.

Try:

...
if choice == '1':
   input("Please choose your target: ")
   ...

Alternatively if you want numerical values for 'choice', you can convert input string to integer:

choice = int(input("Enter your choice [1 - 3]: "))

But this will fail if user types non-numerical value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文