Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- #-------------------------------------#
- #BotNet's GUI version, created by _jun#
- #-------------------------------------#
- import wx
- from socket import *
- import thread
- import sys
- from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
- #color
- global red
- red = '\033[31m'
- global green
- green = '\033[32m'
- global reset
- reset = '\033[0m'
- global yellow
- yellow = '\033[33m'
- global cyan
- cyan = '\033[36m'
- global magenta
- magenta = '\033[35m'
- global cls
- cls = '\33c'
- #end color
- class AutoWidthListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):
- def __init__(self, parent):
- wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)
- ListCtrlAutoWidthMixin.__init__(self)
- class Server():
- """ The server class, with his configuration and his functions """
- def __init__(self):
- self.host = '192.168.0.20'
- self.port = 55568
- self.buf = 1024
- self.addr = (self.host, self.port)
- self.serversocket = socket(AF_INET, SOCK_STREAM)
- self.serversocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
- self.serversocket.bind(self.addr)
- def handler(self, clientsocket, clientaddr):
- self.lastmsg = str(clientsocket.recv(4096))
- print(self.lastmsg)
- def listen(self, port, serversocket):
- serversocket.listen(5)
- token = 1
- while token == 1:
- print("Server is listening on port {}.".format(port))
- self.clientsocket, self.clientaddr = self.serversocket.accept()
- print("Connection from ", self.clientsocket.getpeername())
- thread.start_new_thread(self.handler,(self.clientsocket, self.clientaddr))
- token = 0
- self.client_address = str(self.clientaddr)
- cl = Clients(self.clientaddr)
- class Clients(Server):
- """ The clients class, which have all clients in it."""
- def __init__(self, address='N/A', lastmsg='N/A', status='N/A'):
- clients = [(address, lastmsg, status)]
- class ClientsList(wx.Frame):
- """The List of the clients, in middle of the main window"""
- def __init__(self, parent, id, title):
- wx.Frame.__init__(self, parent, id, title, size=(700, 200))
- hbox = wx.BoxSizer(wx.HORIZONTAL)
- panel = wx.Panel(self, -1)
- self.list = AutoWidthListCtrl(panel)
- self.list.InsertColumn(0, 'Address', width=150)
- self.list.InsertColumn(1, 'Last Message', width=450)
- self.list.InsertColumn(2, 'Status', wx.LIST_FORMAT_RIGHT, 20)
- global clients
- clients = [('N/A', 'N/A', 'N/A')]
- for i in clients:
- index = self.list.InsertStringItem(sys.maxint, i[0])
- self.list.SetStringItem(index, 1, i[1])
- self.list.SetStringItem(index, 2, i[2])
- hbox.Add(self.list, 1, wx.EXPAND)
- panel.SetSizer(hbox)
- self.Centre()
- self.Show(True)
- class Window(wx.Frame):
- """ The window class, with the events, the config, and the initialization of the window"""
- def __init__(self, *args, **kwargs):
- super(Window, self).__init__(*args, **kwargs)
- self.InitUI()
- self.SetSize((800,350))
- self.SetTitle('BotNet')
- self.Centre()
- self.Show(True)
- #Initialization of the server
- global serv
- serv = Server()
- #Initialization of the main window
- def InitUI(self):
- #Toolbar
- self.toolbar = self.CreateToolBar()
- tserver = self.toolbar.AddLabelTool(
- wx.ID_ANY, '', wx.Bitmap('server.png'))
- self.toolbar.AddSeparator()
- tsettings = self.toolbar.AddLabelTool(
- wx.ID_ANY, '', wx.Bitmap('settings.png'))
- self.toolbar.Realize()
- #Panel
- panel = wx.Panel(self)
- vbox = wx.BoxSizer(wx.VERTICAL)
- hbox1 = wx.BoxSizer(wx.HORIZONTAL)
- listenBtn = wx.Button(panel, label='Listen', size=(100, 30))
- stopBtn = wx.Button(panel, label='Stop', size=(100,30))
- hbox1.Add(listenBtn)
- hbox1.Add(stopBtn)
- vbox.Add(hbox1, flag=wx.ALIGN_LEFT | wx.TOP | wx.LEFT, border=10)
- panel.SetSizer(vbox)
- #Clients list
- ClientsList(None, -1, 'clients')
- #Binding
- self.Bind(wx.EVT_BUTTON, self.onListenClick, listenBtn)
- self.Bind(wx.EVT_BUTTON, self.onStopClick, stopBtn)
- #Events
- def onQuit(self, e):
- self.Close()
- def onListenClick(self, e):
- serv.listen(serv.port, serv.serversocket)
- def onStopClick(self, e):
- serv.clientsocket.shutdown(SHUT_RD | SHUT_WR)
- serv.clientsocket.close()
- print(red+"Connection Closed."+reset)
- #Main Function
- def main():
- app = wx.App()
- Window(None)
- app.MainLoop()
- if __name__ == '__main__':
- #We call the program
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement