import requests import json class PythonController: def __init__(self, http_server: str): self.http_server = http_server def _execute_python_command(self, command: str) -> None: payload = json.dumps({ "command": command }) headers = { 'Content-Type': 'application/json' } try: response = requests.post(self.http_server + "/execute", headers=headers, data=payload) if response.status_code == 200: print("Command executed successfully:", response.text) else: print("Failed to execute command. Status code:", response.status_code) except requests.exceptions.RequestException as e: print("An error occurred while trying to execute the command:", e) # example usage if __name__ == '__main__': # replace with your actual server URL of the vm server_url = "http://192.168.7.129:5000" controller = PythonController(server_url) # example commands python_command = "python -c \"import keyboard; keyboard.write('hello world')\"" python_command = "python -c \"import mouse; mouse.move(100,100);mouse.right_click()\"" controller._execute_python_command(python_command)