from tkinter import *
import tkinter as ttk
import tkinter as tk
import tkinter.messagebox
import sys,os,random,subprocess,socket,threading,time
from queue import Queue
#Author Caleb Fahlgren
#Security Tool
#Home Window
class Window1(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
#Menu Bar Widgets
#<----------------------------------------------------Server.Stream>
#Packet sender Window Code
def sendtcp(self):
self.newWindow = tk.Toplevel(self.master)
self.app = Window2(self.newWindow)
def sendUDP(self):
self.newWindow2 = tk.Toplevel(self.master)
self.app = SendUDP(self.newWindow2)
def initUI(self):
self.parent.title("Multipurpose Security Tool")
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
#File Menu Code
#<---------------------------------------------------->
fileMenu = Menu(menubar, tearoff=0)
fileMenu.add_command(label="New",command=self.new)
fileMenu.add_separator()
fileMenu.add_command(label="Save")
fileMenu.add_separator()
fileMenu.add_command(label="Save as")
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=self.onExit)
menubar.add_cascade(label="File", menu=fileMenu)
#<----------------------------------------------------->
#Capture Menu Code
#<----------------------------------------------------->
captureMenu = Menu(menubar, tearoff=0,)
#Submenu Send Packet
#<----------------------------------------------------->
submenu = Menu(captureMenu, tearoff=0)
submenu.add_command(label="Send TCP Packet",command=self.sendtcp)
submenu.add_command(label="Send UDP Packet", command=self.sendUDP)
captureMenu.add_cascade(label="Send Packet", menu=submenu, underline=0)
captureMenu.add_separator
#<----------------------------------------------------->
#Regular Menu Widgets under Capture
captureMenu.add_separator()
captureMenu.add_command(label="TCP Packet Analyzer")
captureMenu.add_separator()
captureMenu.add_command(label="UDP Packet Analyzer")
captureMenu.add_separator()
captureMenu.add_command(label="Whois Lookup")
menubar.add_cascade(label="Capture", menu=captureMenu)
#<----------------------------------------------------->
def showMenu(self, e):
self.menu.post(e.x_root, e.y_root)
#Exit Code on MenuBar
def onExit(self):
quitquestion = tkinter.messagebox.askquestion("Quit","Are you sure you want to quit?")
if quitquestion == "yes":
self.quit()
#New Code on MenuBar
def new(self):
python = sys.executable
os.execl(python, python, * sys.argv)
#UDP Packet Sender
class Window2(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI2()
#Exit Code on MenuBar
def onExit(self):
self.parent.destroy()
#<----------------------------------------------------->
def initUI2(self):
self.frame = tk.Frame(self.master)
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
fileMenu = Menu(menubar, tearoff=0)
fileMenu.add_command(label="Exit",command=self.onExit)
menubar.add_cascade(label="File", menu=fileMenu)
self.parent.title("Send TCP Packet")
self.parent.geometry("500x300+400+200")
self.webaddresstcp = Entry(self, width=50,bg='gray')
self.waltcp = Label(self,text="Address",font=("Helvetica", 12),fg="green")
self.messagetcp = Entry(self, width=50,bg='gray')
self.messagelabeltcp = Label(self, text="Message",font=("Helvetica", 12),fg="green")
self.runbuttontcp=Button(self, text="Run",bg='green',activebackground="yellow",command=self.sendscripttcp)
self.portnumbertcp = Entry(self,width=15,bg='gray')
self.portlabeltcp = Label(self, text="Port",font=("Helvetica", 12),fg="green")
self.waltcp.pack()
self.webaddresstcp.pack()
self.messagelabeltcp.pack()
self.messagetcp.pack()
self.portlabeltcp.pack()
self.portnumbertcp.pack()
self.runbuttontcp.pack()
self.pack()
def onExit(self):
self.parent.destroy()
def sendscripttcp(self):
这是我想要将tcp数据包发送到IP地址和用户在GUI窗口的“输入”框中键入的端口的位置。但每次我跑它,我得到。
sock.sendto(bytes(TCPMESSAGE,“utf-8”),(TCP_IP,int(TCP_PORT))) BrokenPipeError:[Errno 32]管道破损
但是当我运行UDP Script Packet Sender时它工作得很好。我还想确保在发送之前对所有内容进行编码。 :)
try:
TCP_IP = socket.gethostbyname("%s" % (self.webaddresstcp.get()))
TCP_PORT ="%s" % (self.portnumbertcp.get())
TCPMESSAGE = "%s" % (self.messagetcp.get())
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP
sock.sendto(bytes(TCPMESSAGE, "utf-8"), (TCP_IP, int(TCP_PORT)))
sock.close()
tkinter.messagebox.showinfo('TCP INFO', 'TCP Target IP ' + TCP_IP + '\n' + 'TCP Target Port: ' + TCP_PORT + '\n' + 'Packet Data: ' + TCPMESSAGE)
except ValueError:
tkinter.messagebox.showinfo('Value Error','You did not input anything into entry boxes!')
class SendUDP(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI3()
def initUI3(self):
self.frame = tk.Frame(self.master)
self.parent.title("Send UDP Packet")
self.parent.geometry("500x300+400+200")
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
fileMenu = Menu(menubar, tearoff=0)
fileMenu.add_command(label="Exit",command=self.onExit)
menubar.add_cascade(label="File", menu=fileMenu)
self.webaddress = Entry(self, width=50,bg='gray')
self.wal = Label(self,text="Address",font=("Helvetica", 12),fg="green")
self.message = Entry(self, width=50,bg='gray')
self.messagelabel = Label(self, text="Message",font=("Helvetica", 12),fg="green")
self.runbutton=Button(self, text="Run",bg='green',activebackground="yellow",command=self.sendscript)
self.portnumber = Entry(self,width=15,bg='gray')
self.portlabel = Label(self, text="Port",font=("Helvetica", 12),fg="green")
self.wal.pack()
self.webaddress.pack()
self.messagelabel.pack()
self.message.pack()
self.portlabel.pack()
self.portnumber.pack()
self.runbutton.pack()
self.pack()
def onExit(self):
self.parent.destroy()
def sendscript(self):
try:
UDP_IP = socket.gethostbyname("%s" % (self.webaddress.get()))
UDP_PORT ="%s" % (self.portnumber.get())
MESSAGE = "%s" % (self.message.get())
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, int(UDP_PORT)))
tkinter.messagebox.showinfo('UDP INFO', 'UDP Target IP ' + UDP_IP + '\n' + 'UDP Target Port: ' + UDP_PORT + '\n' + 'Packet Data: ' + MESSAGE)
sock.close()
except ValueError:
tkinter.messagebox.showinfo('Value Error','You did not input anything into entry boxes!')
#Windows Settings
def main():
#<----------------------------------------------------->
root = Tk()
root.geometry("600x480+400+100")
app = Window1(root)
#Page 1 and Page 2 Tab
root.mainloop()
#<----------------------------------------------------->
if __name__ == '__main__':
main()