First files upload.
This commit is contained in:
1 parent
bccce9a23e
commit
282e73cb05
2 files changed
+70
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import subprocess
|
||||
from flask import Flask, render_template_string, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
HTML_TEMPLATE = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>IPv6 Subnet Calculator</title>
|
||||
<style>
|
||||
body { font-family: monospace; background: #1e1e2e; color: #cdd6f4; padding: 20px; }
|
||||
input, button { padding: 10px; font-size: 16px; border-radius: 4px; border: none; }
|
||||
input { width: 350px; background: #313244; color: #fff; }
|
||||
button { background: #89b4fa; color: #11111b; cursor: pointer; font-weight: bold; }
|
||||
pre { background: #181825; padding: 15px; border-radius: 6px; border: 1px solid #45475a; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>IPv6 Subnet Calculator (sipcalc Wrapper)</h2>
|
||||
<form method="POST">
|
||||
<input type="text" name="ipv6" placeholder="2001:db8:85a3::8a2e:370:7334/64" value="{{ query }}">
|
||||
<button type="submit">Calculate</button>
|
||||
</form>
|
||||
{% if output %}
|
||||
<h3>Results:</h3>
|
||||
<pre>{{ output }}</pre>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
@app.route("/", methods=["GET", "POST"])
|
||||
def index():
|
||||
output = ""
|
||||
query = ""
|
||||
if request.method == "POST":
|
||||
query = request.form.get("ipv6", "").strip()
|
||||
if query:
|
||||
try:
|
||||
# Run sipcalc CLI command securely
|
||||
result = subprocess.run(
|
||||
["sipcalc", query], capture_output=True, text=True, timeout=5
|
||||
)
|
||||
output = result.stdout if result.returncode == 0 else result.stderr
|
||||
except Exception as e:
|
||||
output = str(e)
|
||||
return render_template_string(HTML_TEMPLATE, query=query, output=output)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
Reference in new issue
Block a user