[python]DNS resolution webapp with flask

Very simple webapp, I still need to do some styling with CSS… this is a simple concept.
here’s an example:
Screen Shot 2018-05-20 at 11.11.59 PM

The output will be:
Screen Shot 2018-05-20 at 11.12.55 PM

Here are the jinja2 templates:
Screen Shot 2018-05-20 at 11.13.42 PM.png

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)
Advertisement

2 thoughts on “[python]DNS resolution webapp with flask

  1. 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) }}

  2. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s