Very simple webapp, I still need to do some styling with CSS… this is a simple concept.
here’s an example:
The output will be:
Here are the jinja2 templates:
Here’s the code.
from flask import Flask, request, render_template import socket def host_processing(host): answer = "" try: answer = socket.gethostbyname(host) except Exception: # If not resolvable, dun care. pass if answer: return answer else: return host app = Flask(__name__) @app.route('/') def main_form(): return render_template('tool.html') @app.route('/', methods=['POST']) def post_form(): answers = [] hosts = request.form['text'].split(',') for host in hosts: answers.append(host_processing(host)) return render_template('answers.html', answers=answers) if __name__ == '__main__': app.run(debug=True)
If you want the output not to be a list, and want to separate them as commas use take out all for loop in the template, and insert {{ ‘,’.join(answers) }}
To publish the flask to external for demonstration, do this render_template(debug=True,host=’0.0.0.0′), else the webservice will only be accessible by localhost.