Created
December 17, 2023 20:42
-
-
Save jbdesbas/bcc8398c98d4985a5070e66a699a2e74 to your computer and use it in GitHub Desktop.
pocsag log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import threading | |
import sys | |
import logging | |
import locale | |
import re | |
from datetime import datetime | |
locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') | |
channels = [ | |
(9997,'466.040MHz'), | |
(9998,'466.195MHz'), | |
(9999,'466.165MHz') | |
] | |
# Fonction pour écouter une connexion UDP | |
def ecouter_udp(port, freq): | |
# Créer une socket UDP | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: | |
# Associer la socket au port spécifié | |
s.bind(('127.0.0.1', port)) | |
print(f"Écoute sur le port UDP {port}") | |
# Boucle d'écoute | |
while True: | |
# Recevoir les données | |
data, addr = s.recvfrom(1024) | |
mess = decode_message(data.decode('latin-1')) | |
logging.info(f"{freq}\t{mess['date']}\t{mess['address']}\t{mess['type']}\t{mess['payload']}") | |
def decode_message(message): | |
expr = r"([\w]*\. [\w]*\. \d{1,2} \d{2}:\d{2}:\d{2} \d{4})(\d*)(.*)" # reg pour séparer la date iso, l'adresse(+type) et le contenu | |
match = re.search(expr, message) | |
date_iso = match.group(1) | |
date = datetime.strptime(date_iso, "%a %b %d %H:%M:%S %Y") # Utiliser la date au niveau du script ? | |
address = match.group(2)[:-1] | |
mtype = match.group(2)[-1] | |
payload = match.group(3) | |
return {'date':date, 'address': address, 'type':mtype, 'payload':payload} | |
logging.basicConfig(filename='pocsag.log', encoding='utf-8', level=logging.DEBUG, format="%(message)s") | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
# Créer un thread pour chaque connexion UDP | |
threads = [] | |
for port, freq in channels: | |
t = threading.Thread(target=ecouter_udp, args=(port,freq,)) | |
threads.append(t) | |
t.start() | |
# Attendre que tous les threads se terminent | |
for t in threads: | |
t.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment