Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from Tkinter import *
- import threading
- import socket
- class Manager(object):
- def __init__(self):
- self.address = []
- self.connction = []
- self.GUI1 = Tk()
- self.GUI1.title('welcome to admin control')
- self.GUI1.geometry('800x800')
- self.ListTargets = Listbox(self.GUI1, width=95, fg='green', bg='black', font=2)
- self.ListTargets.pack()
- self.butt = Button(self.GUI1, text='reflesh', font=5, command=self.numberConns)
- self.butt.pack(anchor=CENTER)
- OpenConnction = threading.Thread(target=self.StartSockets)
- OpenConnction.daemon = True
- OpenConnction.start()
- mainloop()
- def StartSockets(self):
- host = '127.0.0.1'
- port = 4434
- while True:
- try:
- self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- # solution for "[Error 89] Address already in use". Use it before bind()
- self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- self.s.bind((host, port))
- self.s.listen(20)
- while True:
- try:
- conn, addr = self.s.accept()
- conn.setblocking(1)
- self.connction.append(conn)
- self.address.append(addr)
- print 'hello', addr
- except Exception, e:
- print 'problem with accept'
- print 'exception:', e
- except Exception, e:
- print 'problem with socket, bind or listen'
- print 'exception:', e
- # close all socket
- for c in self.connction:
- c.close()
- self.s.close()
- # clear all lists
- self.connction = []
- self.address = []
- def numberConns(self):
- # remove all elements from listbox
- self.ListTargets.delete(0, 'end')
- # add all elements again to listbox
- for addr in self.address:
- self.ListTargets.insert('end', addr)
- # --- main ---
- Manager()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement