-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·38 lines (35 loc) · 1.21 KB
/
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
34
35
36
37
38
#!/usr/bin/env python3
from flask import Flask, request, render_template
from urllib.parse import urlparse
import requests
import tldextract
import ipaddress
app = Flask(__name__)
@app.route('/')
def index():
url = request.args.get('url')
if url:
parsed_url = urlparse(url)
if not parsed_url.scheme:
if url.startswith("http:///"):
url = "http://" + url[len("http:///"):]
else:
url = "http://" + url
if not parsed_url.netloc:
if url.startswith("http:///"):
url = url.replace("http:///", "http://")
elif url.startswith("https:///"):
url = url.replace("https:///", "https:///")
extracted = tldextract.extract(url)
if extracted.suffix:
domain = extracted.registered_domain
try:
ip = str(ipaddress.ip_address(domain))
url = url.replace(domain, ip)
except ValueError:
pass
response = requests.get(url)
return render_template('index.html', response_text=response.text)
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, debug=False)