This commit is contained in:
Matěj Divecký 2022-07-17 13:10:03 +02:00
commit 8b1cb6f23c
4 changed files with 69 additions and 0 deletions

4
Dockerfile Normal file
View file

@ -0,0 +1,4 @@
FROM python:3.9.1-slim
ADD ./app /python-flask
WORKDIR /python-flask
RUN pip install -r requirements.txt

52
app/main.py Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/python3
# import dns.resolver
# import dns.reversename
# import sys
# from whois import whois
import requests
import json
from flask import Flask
# from flask import jsonify
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
# def get_ip(domain):
# ip_rq = dns.resolver.resolve(domain, 'A')
# ip = ip_rq[0].to_text()
# return(ip)
# def get_ptr(ip):
# ip_rev = dns.reversename.from_address(ip)
# ptr_rq = dns.resolver.resolve(ip_rev, 'PTR')
# ptr = ptr_rq[0].to_text()
# return(ptr)
def ip_api(ip):
rq_url = "http://ip-api.com/json/" + ip + "?fields=17006105"
rq = requests.get(rq_url)
response = rq.json()
#return Response(json.dumps(response), mimetype='application/json')
return response
@app.route('/<string:input>', methods=['GET'])
def ipinfo(input):
ip_info = ip_api(input)
return(ip_info)
if __name__ == '__main__':
app.run(host="0.0.0.0")

3
app/requirements.txt Normal file
View file

@ -0,0 +1,3 @@
dnspython
Flask
requests

10
docker-compose.yml Normal file
View file

@ -0,0 +1,10 @@
version: "3.8"
services:
app:
build: .
command: python main.py
ports:
- "5000:5000"
volumes:
- ./app:/python-flask
container_name: resolv