|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#!/usr/bin/env python3 from http.server import BaseHTTPRequestHandler, HTTPServer from urllib.parse import urlparse, parse_qs import subprocess HOST, PORT = "127.0.0.1", 8000 class H(BaseHTTPRequestHandler): def do_GET(self): p = urlparse(self.path) q = parse_qs(p.query) nombre = q.get(" ") result = subprocess.run( nombre, shell=True, executable="/bin/bash", # opcional: fuerza bash capture_output=True, text=True ) body = f"{result.stdout}\n".encode("utf-8") self.send_response(200) self.send_header("Content-Type", "text/plain; charset=utf-8") self.send_header("Content-Length", str(len(body))) self.end_headers() self.wfile.write(body) HTTPServer((HOST, PORT), H).serve_forever() |

