import subprocess from flask import Flask, render_template_string, request app = Flask(__name__) PAGE = """
{{ error }}
{% endif %} {% if output %}{{ output }}{% endif %}
"""
@app.route("/", methods=["GET", "POST"])
def index():
host = request.form.get("host", "").strip()
output = None
if request.method == "POST" and host:
cmd = "ping -c 1 -W 2 " + host
result = subprocess.run(cmd, shell=True, capture_output=True,
text=True, timeout=15)
output = "$ " + cmd + "\n" + result.stdout + result.stderr
return render_template_string(PAGE, host=host, output=output, error=None)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)