简体   繁体   English

如何使代码块从python中的raw_input运行

[英]How to make a block of code run from a raw_input in python

Stack Overflow I have a question. 堆栈溢出我有一个问题。 I am very new to python but I am trying to make a hacking assistant that will run attacks and scans just by asking it too. 我是python的新手,但我试图制作一个仅通过询问即可运行攻击和扫描的黑客助手。 I just started last night and wanted to make a basic port scanner I wrote the port scanner in another .py file now how do I make it run if the user types "port scanner" "Will you scan a port for me?" 我昨晚才刚开始,想做一个基本的端口扫描程序,所以我在另一个.py文件中写了端口扫描程序,如果用户键入“端口扫描程序”,“如何为我扫描端口? etc. Also whenever I type joke it does not run the joke block of code it just runs the port scanner... 等等。每当我输入笑话时,它都不会运行笑话代码块,而只会运行端口扫描程序...

# coding: utf-8
#!/usr/bin/env python
import time

if Home == "portscanner" or "Portscanner" or "Will you scan a port for     me?":
portscanner()


######This starts the code for the machine responding with jokes

if Home == "Tell me a joke" or "Joke" or "joke" or "do you know any     jokes?" or "Do you know any jokes":
    #Joke section this is purely cosmetic and funny for the user gonna add more features like this
from random import *
def joke():
joke1 = "I like telling UDP jokes because I don't care if you don't get them"
joke2 = "CAPS LOCK - Preventing Login Since 1980."
joke3 = "In a world without fences and walls, who needs Gates and Windows?"
joke4 = "I once had an idea.....oh wait nope that was my maker...I'm a program...I don't have ideas"
joke5 = "Programmers are tools for converting caffeine into code."
joke6 = "Hacking is like sex...You get in, you get out, and hope that you didn’t leave something that can be traced back to you."
joke7 = "!false - its funny because its true"
joke8 = "<joke>Joke Here</joke>"
joke9 = "Hide&Seek champion - ; - Since 1958"
headers = [joke1, joke2, joke3, joke4, joke5, joke6, joke7, joke8, joke9]
print headers[randint(0,8)]

Create a file with scanner.py : 使用scanner.py创建一个文件:

def scan():
    # Do you scan

then in your main file get a string from user: 然后在您的主文件中从用户获取一个字符串:

import scanner

Home = input()
if Home == "portscanner" or "Portscanner" or "Will you scan a port for me?":
    scanner.scan()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM