Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telnetlib
- import tkinter as tk
- from tkinter.scrolledtext import ScrolledText
- session = telnetlib.Telnet()
- # Root object
- root = tk.Tk()
- root.title("Telnet")
- # KNAPPA - frame
- buttonFrame = tk.Frame(root)
- buttonFrame.grid(row=0, column=0)
- # OUTPUT - Frame
- textFrame = tk.Frame(root)
- textFrame.grid(row=1, column=0)
- # OUTPUT - text
- st = ScrolledText(root)
- st.grid(row=0, column=1)
- st.tag_config('in', foreground='red')
- st.tag_config('out', foreground='black')
- # TEXT FIELDS - variables
- #..
- def topen():
- global session
- session = telnetlib.Telnet("arnold", "25")
- tRead("open arnold 25\n")
- def thelo():
- session.write(("helo domain.ru\n").encode('ascii'))
- tRead("helo domain.ru\n")
- def tauth():
- session.write(("AUTH LOGIN\n").encode('ascii'))
- tRead("AUTH LOGIN\n")
- def tusername():
- session.write(("MkBlbWlsZS5zZQ==\n").encode('ascii'))
- tRead("MkBlbWlsZS5zZQ==\n")
- def tpassword():
- session.write(("cXdlcg==\n").encode('ascii'))
- tRead("cXdlcg==\n")
- def tmailfrom():
- session.write(("mail from emile@domain.ru\n").encode('ascii'))
- tRead("mail from emile@domain.dom\n")
- def trcpt():
- session.write(("rcpt to 1@emile.se\n").encode('ascii'))
- tRead("rcpt to 1@emile.se\n")
- def tdata():
- session.write(("data\n").encode('ascii'))
- tRead("data\n")
- def tdataContent():
- session.write(("From: emile@domain.ru\nSender: emile@domain.ru\nSubject telnet mejl\ncontent\n.\n").encode('ascii'))
- tRead("From: emile@domain.ru\nSender: emile@domain.ru\nSubject telnet mejl\ncontent\n.\n")
- def tquit():
- session.write(("quit\n").encode('ascii'))
- tRead("quit\n")
- def tRead(sentMsg):
- message = session.read_until(b'\n')
- # sent
- st.insert(tk.END, '--> ' + sentMsg, 'out')
- # received
- st.insert(tk.END, '<-- '.encode('ascii') + message, 'in')
- # KNAPPAR - funktioner
- bOpen = tk.Button(buttonFrame, text='open', command=topen)
- bHello = tk.Button(buttonFrame, text='HELO', command=thelo)
- bAuth = tk.Button(buttonFrame, text='Auth', command=tauth)
- bUsername = tk.Button(buttonFrame, text='Username', command=tusername)
- bPassword = tk.Button(buttonFrame, text='Password', command=tpassword)
- bMailfrom = tk.Button(buttonFrame, text='Mailfrom', command=tmailfrom)
- bRcpt = tk.Button(buttonFrame, text='Rcpt', command=trcpt)
- bData = tk.Button(buttonFrame, text='Data', command=tdata)
- bDataContent = tk.Button(buttonFrame, text='DataContent', command=tdataContent)
- bQuit = tk.Button(buttonFrame, text='QUIT', command=tquit)
- bExit = tk.Button(buttonFrame, text='Exit', command=root.destroy)
- # KNAPPAR - pack
- bOpen.pack(fill='both')
- bHello.pack(fill='both')
- bAuth.pack(fill='both')
- bUsername.pack(fill='both')
- bPassword.pack(fill='both')
- bMailfrom.pack(fill='both')
- bRcpt.pack(fill='both')
- bData.pack(fill='both')
- bDataContent.pack(fill='both')
- bQuit.pack(fill='both')
- bExit.pack(fill='both')
- # Show frame
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement