from glob import escape
from flask import Flask,request,json
from markupsafe import escape
import os
import requests
import datetime
app = Flask(__name__)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
greet = '
You should not be here!
'
link = 'Click me!
'
return greet + link
@app.route('/ping/')
def ping(name):
response = os.system("ping -c 1 " + name)
now = str(datetime.datetime.now())
if response == 0:
instruc = ' up'
else:
instruc = ' down'
return now + instruc
@app.route('/http/')
def http(name):
address = 'http://%s' %name
now = str(datetime.datetime.now())
try:
r = requests.get(address)
status = r.status_code
status_string = ' %s' %str(status)
except requests.exceptions.Timeout:
status_string = " Timeout"
except requests.exceptions.TooManyRedirects:
status_string = " TooManyRedirects"
except requests.exceptions.RequestException as e:
status_string = ' %s' %str(e)
return now + status_string
@app.route('/https/')
def https(name):
address = 'https://%s' %name
try:
r = requests.get(address)
status = r.status_code
status_string = ' %s' %str(status)
except requests.exceptions.Timeout:
status_string = " Timeout"
except requests.exceptions.TooManyRedirects:
status_string = " TooManyRedirects"
except requests.exceptions.RequestException as e:
status_string = ' %s' %str(e)
return now + status_string
if __name__ == '__main__':
app.run(debug=True)