# # Copyright (C) John Solntsev (2024) # # This file is part of hwmon-checker. # # hwmon-checker is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # hwmon-checker is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with hwmon-checker. If not, see . import socket from hwmon import HardwareMonitor if __name__ == "__main__": hwmon = HardwareMonitor() socket.setdefaulttimeout(5) serv_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serv_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) serv_sock.bind(("", 9900)) serv_sock.listen() while True: try: client, addr = serv_sock.accept() except TimeoutError: continue try: recv_data = client.recv(25) if recv_data == b"GET_MON_ALL": hwmon.check_all() client.send("{}".format(hwmon.get_json()).encode("utf-8")) else: client.send(b"ERR 1 Bad Request") except BrokenPipeError: pass except TimeoutError: pass finally: client.close()