[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)
Advertisements
This entry was posted in Python, Scripting and tagged , , . Bookmark the permalink.

2 Responses to [python]DNS resolution webapp with flask

  1. cyruslab says:

    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. cyruslab says:

    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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

w

Connecting to %s