Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2022 10:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Creates logs for APs in the network, in a temporary directory.
A script to write log files in the /tmp/migrationlogs
directory, and reports changes using the difference between
the current AP state and the log file state, to provide
stations that made it into the AP range.
This information can be used to provide new stations that
have entered the AP range.
from pathlib import Path
import os
import difflib
import re
import shutil
def log_it(wlan, content):
This function creates log files and updates them
when changes are detected, and returns the diff.
original_content = content
content = content.split("\n")
# creating a directory in the `tmp` folder to
# store the migration logs
dir_change = Path("/tmp/migrationlogs")
# creating log files to monitor the network
path = Path(f"log-{wlan}.txt")
change_required = True
refreshed_stations = set()
# checks if the log file for the AP exists or
# not, and if it doesn't, create it.
if path.is_file():
with open(f"log-{wlan}.txt", "r") as f:
file_contents ="\n")
# if no change in the contents of the log,
# then there are no changes required
if content == file_contents:
change_required = False
# If changes are requred, write to the log
# file, get the difference between the
# previous version and the new version.
if change_required == True:
with open(f"log-{wlan}.txt", "w") as f:
d = difflib.Differ()
# If a station has been added, append it
# to the list which is checked for changes
for entry in list(, content)):
if entry[0] != "+":
station_id = entry[10:27]
if"..:..:..:..:..:..", station_id):
with open(f"log-{wlan}.txt", "w") as f:
return refreshed_stations
def book_it():
Remove the directory where the migration logs
are present entirely. This function is triggered
when the migrator is shut down.
if __name__ == "__main__":
# log_it('wlan', 'testing123')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment