Answer the question
In order to leave comments, you need to log in
The data is "cut off" when the sniffer is running. How to fix?
Hello!
I am learning to work with Python 3, trying to get data from a network device using a sniffer:
import re
from PyQt5 import QtCore
from scapy.all import *
class TestSniffer(QtCore.QThread):
def __init__(self, data, parent=None):
QtCore.QThread.__init__(self, parent)
self.data = data
def run(self):
sniff(prn=self.pkt_callback, filter="tcp", store=0)
def pkt_callback(self, pkt):
# Фильтруем пакеты по мак-адресу
if pkt.src == "мак_адрес_устройства":
if pkt.getlayer(Raw):
data_dirty = pkt[Raw].load
try:
# "Расшифровываем" данные пакета
data_decoded = data_dirty.decode("utf-8")
print(data_decoded)
# Ищем текст между тэгами
check_data = re.findall("<text .*>(.*?)</text>", data_decoded)
for line in check_data:
if "Test" not in line:
self.data.append(line)
print(self.data)
if len(self.data) == 6:
print("Good")
self.data = []
except Exception as error:
print("Error: ", error)
<a id="19">
<text font-family="monospace" font-size="10">001</text>
<text font-family="monospace" font-size="10">Test</text>
</a>
<a id="20">
<text font-family="monospace" font-size="10">002</text>
<text font-family="monospace" font-size="10">Test</text>
</a>
<a id="21">
<text font-family="monospace" font-size="10">003</text>
<text font-family="monospace" font-size="10">Test</text>
</a>
<a id="22">
<text font-family="monospace" font-size="10">0
04</text>
<text font-family="monospace" font-size="10">Test</text>
</a>
<a id="23">
<text font-family="monospace" font-size="10">005</text>
<text font-family="monospace" font-size="10">Test</text>
</a>
<a id="24">
<text font-family="monospace" font-size="10">006</text>
<text font-family="monospace" font-size="10">Test</text>
</a>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question