-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
33 lines (24 loc) · 772 Bytes
/
app.py
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
33
import subprocess
from waitress import serve
from flask import Flask, render_template, request
app = Flask(__name__, template_folder='templates')
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
@app.route('/', methods=['POST'])
def submit():
text = request.form['text']
if text:
try:
output = subprocess.check_output(f'ping -c1 {text}', shell=True)
except subprocess.CalledProcessError:
output = None
if output:
result = output.decode("utf-8")
else:
result = 'no pong'
else:
result = 'please enter an address'
return render_template('index.html', output=result)
if __name__ == '__main__':
serve(app, host='0.0.0.0')