def test_StopCapture(self): capture = LiveCapture() capture.startLiveCapture() packet1 = IP(dst="10.4.12.91")/ICMP()/"HelloWorld" packet2 = IP(dst="10.4.12.91")/TCP(dport=23) packets = [packet1, packet2, packet1, packet2, packet1, packet2, packet1, packet2, packet1, packet2] for packet in packets: send(packet, iface='lo') capture.stopLiveCapture() for (packetA, packetB) in zip(capture.packetList, packets): self.assertEqual(hexdump(packetA[IP]), hexdump(packetB[IP]) )
def startToolButtonClicked(self): self.liveCapture = LiveCapture() iface = InterfaceSelection(self.parent) ifaceName = iface.GetInterface() if ifaceName == None: return self.liveCapture.setInterface(ifaceName) retVal = self.liveCapture.startLiveCapture() if retVal != -1: self.startToolButton.setDisabled(True) self.stopToolButton.setEnabled(True) self.startAction.setDisabled(True) self.stopAction.setEnabled(True) self.packetDataUi = PacketData_ui(self.parent) getPacketThread = GetPacketThread(self.liveCapture, self.packetDataUi)
def test_StopCapture(self): capture = LiveCapture() capture.startLiveCapture() packet1 = IP(dst="10.4.12.91") / ICMP() / "HelloWorld" packet2 = IP(dst="10.4.12.91") / TCP(dport=23) packets = [ packet1, packet2, packet1, packet2, packet1, packet2, packet1, packet2, packet1, packet2 ] for packet in packets: send(packet, iface='lo') capture.stopLiveCapture() for (packetA, packetB) in zip(capture.packetList, packets): self.assertEqual(hexdump(packetA[IP]), hexdump(packetB[IP]))
class LiveCapture_ui(QObject): def __init__(self, parent=None): super(LiveCapture_ui, self).__init__(parent) self.parent = parent self.initUi() self.liveCapture = None self.packetDataUi = None ''' Description: Initialise the buttons and actions to control the live captring of data graphically. Add corresponding actions/tool buttons to toolbars/menubars of the mainWindow ''' def initUi(self): startPixmap = QPixmap( os.path.dirname(os.path.realpath(__file__)) + '/Start.png') stopPixmap = QPixmap( os.path.dirname(os.path.realpath(__file__)) + '/Stop.png') startIcon = QIcon(startPixmap) stopIcon = QIcon(stopPixmap) self.startToolButton = QToolButton(self.parent) self.stopToolButton = QToolButton(self.parent) self.startToolButton.setIcon(startIcon) self.stopToolButton.setIcon(stopIcon) self.startToolButton.setIconSize(QSize(32, 32)) self.stopToolButton.setIconSize(QSize(32, 32)) self.startToolButton.clicked.connect(self.startToolButtonClicked) self.stopToolButton.clicked.connect(self.stopToolButtonClicked) self.startAction = QAction("Start Live Capturing", self.parent) self.startAction.triggered.connect(self.startToolButtonClicked) self.stopAction = QAction("Stop Live Capture", self.parent) self.stopAction.triggered.connect(self.stopToolButtonClicked) # Setup initial values for the buttons/actions self.startToolButton.setEnabled(True) self.stopToolButton.setDisabled(True) self.startAction.setEnabled(True) self.stopAction.setDisabled(True) # Add Actions to the Menu bar menuCapture = self.parent.GetMenu("Capture") if menuCapture != None: menuCapture.addAction(self.startAction) menuCapture.addAction(self.stopAction) menuCapture.addSeparator() # Add tool buttons to the appropriate tool bar toolBarCapture = self.parent.GetToolBar("Capture") if toolBarCapture != None: toolBarCapture.addWidget(self.startToolButton) toolBarCapture.addWidget(self.stopToolButton) ''' Description: Obtain the interface to capture the data from. Check if user has appropriate privilege levels to start capturing data. Toggle tools in the GUI and initialise the packet capturing/display process in separate threads. ''' @pyqtSlot() def startToolButtonClicked(self): self.liveCapture = LiveCapture() iface = InterfaceSelection(self.parent) ifaceName = iface.GetInterface() if ifaceName == None: return self.liveCapture.setInterface(ifaceName) retVal = self.liveCapture.startLiveCapture() if retVal != -1: self.startToolButton.setDisabled(True) self.stopToolButton.setEnabled(True) self.startAction.setDisabled(True) self.stopAction.setEnabled(True) self.packetDataUi = PacketData_ui(self.parent) getPacketThread = GetPacketThread(self.liveCapture, self.packetDataUi) ''' Description: Notify the capturing thread to stop and toggle the buttons in the GUI ''' @pyqtSlot() def stopToolButtonClicked(self): self.startToolButton.setEnabled(True) self.stopToolButton.setDisabled(True) self.startAction.setEnabled(True) self.stopAction.setDisabled(True) self.liveCapture.stopLiveCapture() ''' Description: Description: Wrapper to trigger the Start capturing ''' def triggerStart(self): self.startAction.trigger() ''' Description: Description: Wrapper to trigger the Stop capturing ''' def triggerStop(self): self.stopAction.trigger()
class LiveCapture_ui(QObject): def __init__(self, parent = None): super(LiveCapture_ui, self).__init__(parent) self.parent = parent self.initUi() self.liveCapture = None self.packetDataUi = None ''' Description: Initialise the buttons and actions to control the live captring of data graphically. Add corresponding actions/tool buttons to toolbars/menubars of the mainWindow ''' def initUi(self): startPixmap = QPixmap(os.path.dirname(os.path.realpath(__file__)) + '/Start.png') stopPixmap = QPixmap(os.path.dirname(os.path.realpath(__file__)) + '/Stop.png') startIcon = QIcon(startPixmap) stopIcon = QIcon(stopPixmap) self.startToolButton = QToolButton(self.parent) self.stopToolButton = QToolButton(self.parent) self.startToolButton.setIcon(startIcon) self.stopToolButton.setIcon(stopIcon) self.startToolButton.setIconSize(QSize(32, 32)) self.stopToolButton.setIconSize(QSize(32, 32)) self.startToolButton.clicked.connect(self.startToolButtonClicked) self.stopToolButton.clicked.connect(self.stopToolButtonClicked) self.startAction = QAction("Start Live Capturing", self.parent) self.startAction.triggered.connect(self.startToolButtonClicked) self.stopAction = QAction("Stop Live Capture", self.parent) self.stopAction.triggered.connect(self.stopToolButtonClicked) # Setup initial values for the buttons/actions self.startToolButton.setEnabled(True) self.stopToolButton.setDisabled(True) self.startAction.setEnabled(True) self.stopAction.setDisabled(True) # Add Actions to the Menu bar menuCapture = self.parent.GetMenu("Capture") if menuCapture != None: menuCapture.addAction(self.startAction) menuCapture.addAction(self.stopAction) menuCapture.addSeparator() # Add tool buttons to the appropriate tool bar toolBarCapture = self.parent.GetToolBar("Capture") if toolBarCapture != None: toolBarCapture.addWidget(self.startToolButton) toolBarCapture.addWidget(self.stopToolButton) ''' Description: Obtain the interface to capture the data from. Check if user has appropriate privilege levels to start capturing data. Toggle tools in the GUI and initialise the packet capturing/display process in separate threads. ''' @pyqtSlot() def startToolButtonClicked(self): self.liveCapture = LiveCapture() iface = InterfaceSelection(self.parent) ifaceName = iface.GetInterface() if ifaceName == None: return self.liveCapture.setInterface(ifaceName) retVal = self.liveCapture.startLiveCapture() if retVal != -1: self.startToolButton.setDisabled(True) self.stopToolButton.setEnabled(True) self.startAction.setDisabled(True) self.stopAction.setEnabled(True) self.packetDataUi = PacketData_ui(self.parent) getPacketThread = GetPacketThread(self.liveCapture, self.packetDataUi) ''' Description: Notify the capturing thread to stop and toggle the buttons in the GUI ''' @pyqtSlot() def stopToolButtonClicked(self): self.startToolButton.setEnabled(True) self.stopToolButton.setDisabled(True) self.startAction.setEnabled(True) self.stopAction.setDisabled(True) self.liveCapture.stopLiveCapture() ''' Description: Description: Wrapper to trigger the Start capturing ''' def triggerStart(self): self.startAction.trigger() ''' Description: Description: Wrapper to trigger the Stop capturing ''' def triggerStop(self): self.stopAction.trigger()