From e0e6d2096151daae026b122a3fe025c4b3afe965 Mon Sep 17 00:00:00 2001 From: P7MJ Date: Tue, 10 Feb 2026 14:01:03 -0500 Subject: [PATCH] A-1 Initial Upload Uploaded A-1 --- CLRadio-Reciever.py | 27 ++++++++++ CLRadio-Sender.py | 126 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 CLRadio-Reciever.py create mode 100644 CLRadio-Sender.py diff --git a/CLRadio-Reciever.py b/CLRadio-Reciever.py new file mode 100644 index 0000000..947e252 --- /dev/null +++ b/CLRadio-Reciever.py @@ -0,0 +1,27 @@ +import socket + +def run_server(): + print("=" * 80) + print("CLRadio Reciever Version A-1 | by P7MJ") + print("-" * 80) + host = '0.0.0.0' # Listen on all available interfaces + port = 443 + + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind((host, port)) + s.listen(1) + print(f"Listening on {host}:{port}.") + + c, addr = s.accept() + print(f"Connection established from {str(addr)}") + while True: + data = c.recv(1024).decode() + if not data: + break + print(f"{str(addr)}: {data}") + # Optional: send a response back + # c.send(data.encode()) + c.close() + +if __name__ == '__main__': + run_server() diff --git a/CLRadio-Sender.py b/CLRadio-Sender.py new file mode 100644 index 0000000..6077d16 --- /dev/null +++ b/CLRadio-Sender.py @@ -0,0 +1,126 @@ +import socket +from pathlib import Path + +# ----- KNOWN CONNECTION FILE READ/WRITE/LIST/CLEAR PACKAGE ----- # + +# Read Specific Line Package +def read_specific_line(filename, line_number): # index (0 is first) + with open(filename, 'r') as file: + for index, line in enumerate(file): + if index == line_number: + current_line = line.split() # Splits and removes nick + return current_line[1] + return None + +def known_connection_file(mode, nick, ip_addr, no_of_ip_chosen): # use normal numbers e.g. 1 for first for no_of_ip_chosen + file_path = Path("known_connections.txt") + + if not file_path.exists(): + print(f"Known connections file not found. Creating...", end = " ") + # Create if not exist + with open(file_path, 'w') as f: + f.write("") + print(f"Done.") + + if file_path.exists(): # If file exists: + + # ----- READ MODE ----- # + if mode == "read": # Read out all the lines + with open('known_connections.txt', 'r') as f: + for line in f: + print(f"{line}", end = "") + + # ----- SELECT MODE ----- # + elif mode == "select": + # Find the "no_of_ip_chosen"th line and return the ip address + select_result = read_specific_line("known_connections.txt", no_of_ip_chosen - 1) + if select_result == None: + print("Error: Line does not exist") + else: + return select_result + + # ----- WRITE MODE ----- # + elif mode == "write": + with open('known_connections.txt', 'a') as f: + f.writelines(f"{nick}: {ip_addr}\n") + print("Writing completed.") + + # ----- CLEAR MODE ----- # + elif mode == "clear": + with open('known_connections.txt', 'w') as f: + f.writelines("") + print("File cleared.") + else: + print("Error: Invalid mode.") + +# ---------- PORT SELECTION ---------- # +def port_selection(): + print("=" * 80) + print("CLRadio Sender Version A-1 | by P7MJ") + print("-" * 80) + print("[1] Use/Edit saved ports") + print("[2] Specify port") + user_port_choice = input(" > ") + + # ---------- Use or edit saved ports ---------- # + if user_port_choice == "1": + print("Current Saved Profiles:") + known_connection_file("read", None, None, None) + print("\n[1] Write new profile entry") + print("[2] Select a profile") + print("[3] Clear all profiles (IRREVERSIBLE, WILL ANNIHILATE MASSDEBATER67'S BRAIN)") + profile_user_choice = input(" > ") + + # ----- Write new profile entry ----- # + if profile_user_choice == "1": + profile_nick = input("Profile Nick > ") + profile_ip = input("Profile IP > ") + known_connection_file("write", profile_nick, profile_ip, None) + return 0 + + # ----- Select a profile by number ----- # + elif profile_user_choice == "2": + selection = input("Select by number > ") + if selection.isdigit(): + return known_connection_file("select", None, None, int(selection)) + + # ----- Clear profiles ------ # + elif profile_user_choice == "3": + known_connection_file("clear", None, None, None) + return 0 + + # ---------- + elif user_port_choice == "2": + custom_port = input("Insert custom port > ") + return custom_port + else: + print("Error: You need mental help") + +def run_client(): + while True: + while True: + port_selection_outcome = port_selection() + if port_selection_outcome == 0: + pass + else: + break + # REPLACE WITH YOUR SERVER'S LAN IP ADDRESS + host = port_selection_outcome + port = 443 + + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((host, port)) + + print(f"Server initiated. Sending to: {host}. Enter \"exit\" to exit.") + message = input(" > ") + while message != 'exit': + s.send(message.encode()) + # Optional: receive a response + # data = s.recv(1024).decode() + # print(f"Received from server: {data}") + message = input(" > ") + s.close() + +if __name__ == '__main__': + run_client() +