def packet_selected(self): # on clear self.tab_ethernet_list.clear() self.tab_ip_list.clear() self.tab_protocol_list.clear() # on recupere la selection selected = self.packetsList.selectedItems() selected = selected[0] # on recherche le paquet complet dans currentPackets (le QTreeWidget n'a pas toutes les infos) fullPacket = next((packet for packet in self.currentPackets if packet.id == int(selected.text(1))), None) # premier onglet (hexdump) hexdumpString = hexdump.hexdump(fullPacket.packet, 'return') self.tab_packet_hexdump.setText(hexdumpString) #deuxieme onglet (ethernet) for key,value in fullPacket.layers[0].items() : item = QtGui.QTreeWidgetItem(self.tab_ethernet_list) item.setText(0, str(key)) item.setText(1, str(value)) #troisieme onglet (ip) for key,value in fullPacket.layers[1].items() : item = QtGui.QTreeWidgetItem(self.tab_ip_list) item.setText(0, str(key)) item.setText(1, str(value)) #quatrieme onglet (protocole) self.packetDetail.setTabText(3, fullPacket.layers[2]['LayerType']) for key,value in fullPacket.layers[2].items() : item = QtGui.QTreeWidgetItem(self.tab_protocol_list) item.setText(0, str(key)) item.setText(1, str(value))
# EXEMPLE D'UTILISATION DE LA CLASSE CAPTURE test = capture.Capture() # on lance la capture test.start() time.sleep(10) # on l'arrete test.stopCapture() #on attend la fin du thread test.join() # on boucle sur les paquets recuperes for packet in test.result : print '\n'+'[PACKET TIMESTAMP] : ', packet.created #on boucle sur les layers du paquet for layer in packet.layers : print print 'COUCHE : ', layer['LayerType'] #on boucle sur les items du layer for key, value in layer.items() : if key != 'Data' : print key, value print '\n' hexdump.hexdump(packet.packet) print '\n'
# EXEMPLE D'UTILISATION DE LA CLASSE CAPTURE test = capture.Capture() # on lance la capture test.start() time.sleep(10) # on l'arrete test.stopCapture() #on attend la fin du thread test.join() # on boucle sur les paquets recuperes for packet in test.result: print '\n' + '[PACKET TIMESTAMP] : ', packet.created #on boucle sur les layers du paquet for layer in packet.layers: print print 'COUCHE : ', layer['LayerType'] #on boucle sur les items du layer for key, value in layer.items(): if key != 'Data': print key, value print '\n' hexdump.hexdump(packet.packet) print '\n'