From 08e6572830be6db0650f182ff17256e62b53d432 Mon Sep 17 00:00:00 2001 From: david rice Date: Tue, 7 Apr 2026 15:17:32 +0100 Subject: [PATCH] Added new script --- ai_mgmt.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 ai_mgmt.py diff --git a/ai_mgmt.py b/ai_mgmt.py new file mode 100644 index 0000000..cae6ba9 --- /dev/null +++ b/ai_mgmt.py @@ -0,0 +1,55 @@ +import socket +from smb.SMBConnection import SMBConnection + +SERVER = "192.168.45.4" +SHARE = "AGILENT" +USERNAME = "" # leave empty for guest/anonymous +PASSWORD = "" +CLIENT_NAME = socket.gethostname() +SERVER_NAME = SERVER # use IP for UNC path in TREE_CONNECT + + +def list_csv_files(server, share, username="", password=""): + """Search an SMB1 share recursively and return all .csv file paths.""" + conn = SMBConnection( + username, password, + CLIENT_NAME, SERVER_NAME, + use_ntlm_v2=True, + is_direct_tcp=True # use port 445 directly + ) + + if not conn.connect(server, 445): + print("Failed to connect to the share.") + return [] + + csv_files = [] + + def walk(path): + entries = conn.listPath(share, path) + for entry in entries: + if entry.filename in (".", ".."): + continue + full_path = f"{path}/{entry.filename}" + if entry.isDirectory: + walk(full_path) + elif entry.filename.lower().endswith(".csv"): + csv_files.append(full_path) + + try: + walk("/") + finally: + conn.close() + + return csv_files + + +if __name__ == "__main__": + print(f"Searching \\\\{SERVER}\\{SHARE} for CSV files...\n") + files = list_csv_files(SERVER, SHARE, USERNAME, PASSWORD) + + if files: + print(f"Found {len(files)} CSV file(s):") + for f in files: + print(f" {f}") + else: + print("No CSV files found.")