resolv/app/main.py

53 lines
913 B
Python
Raw Normal View History

2022-07-17 13:10:03 +02:00
#!/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")