2022-07-17 13:10:03 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2022-07-17 16:41:16 +02:00
|
|
|
import dns.resolver
|
|
|
|
import dns.reversename
|
|
|
|
import whois
|
|
|
|
|
|
|
|
import os
|
2022-07-17 13:10:03 +02:00
|
|
|
|
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
|
|
|
|
from flask import Flask
|
|
|
|
# from flask import jsonify
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
|
|
|
|
|
2022-07-17 16:41:16 +02:00
|
|
|
# Host.io is limited do 1000 request/month. And it's only used to show domains on the same IP. It can be disabled while testing to prevent issues.
|
|
|
|
HOSTIO_TOKEN = os.environ['HOSTIO_TOKEN']
|
2022-07-17 17:39:08 +02:00
|
|
|
HOSTIO_ENABLED = os.environ['HOSTIO_ENABLED']
|
2022-07-17 13:10:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2022-07-17 16:41:16 +02:00
|
|
|
def get_ip(domain):
|
|
|
|
ip_rq = dns.resolver.resolve(domain, 'A')
|
|
|
|
ip = ip_rq[0].to_text()
|
|
|
|
return(ip)
|
2022-07-17 13:10:03 +02:00
|
|
|
|
2022-07-17 16:41:16 +02:00
|
|
|
def get_mx(domain):
|
|
|
|
mx_rq = dns.resolver.resolve(domain, 'MX')
|
|
|
|
mx = []
|
|
|
|
for mx_res in mx_rq:
|
|
|
|
mx.append(mx_res.to_text())
|
|
|
|
return(mx)
|
2022-07-17 13:10:03 +02:00
|
|
|
|
|
|
|
def ip_api(ip):
|
|
|
|
rq_url = "http://ip-api.com/json/" + ip + "?fields=17006105"
|
|
|
|
rq = requests.get(rq_url)
|
|
|
|
response = rq.json()
|
2022-07-17 16:41:16 +02:00
|
|
|
return response
|
2022-07-17 13:10:03 +02:00
|
|
|
|
2022-07-17 16:41:16 +02:00
|
|
|
def hostio_api(ip, token):
|
|
|
|
if HOSTIO_ENABLED:
|
|
|
|
rq_url = "https://host.io/api/domains/ip/" + ip + "?token=" + token
|
|
|
|
rq = requests.get(rq_url)
|
|
|
|
response = rq.json()
|
|
|
|
return response
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_whois(domain):
|
|
|
|
response = whois.query(domain)
|
2022-07-17 13:10:03 +02:00
|
|
|
return response
|
|
|
|
|
|
|
|
|
2022-07-17 16:41:16 +02:00
|
|
|
@app.route('/favicon.ico')
|
|
|
|
def ret404():
|
|
|
|
return("Sorry, favicon not here. This is a workaround to not resolve favicon.ico as domain...", 404)
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def homepage():
|
|
|
|
return("This is homepage. Nothing to see here.", 200)
|
|
|
|
|
2022-07-17 13:10:03 +02:00
|
|
|
@app.route('/<string:input>', methods=['GET'])
|
|
|
|
def ipinfo(input):
|
2022-07-17 16:41:16 +02:00
|
|
|
info = {}
|
|
|
|
try:
|
|
|
|
ip = get_ip(input)
|
|
|
|
info['ip'] = ip
|
|
|
|
except:
|
|
|
|
print("DNS IP query failed, exiting.")
|
|
|
|
return("IP could not be resolved. Bye!", 400)
|
|
|
|
|
|
|
|
try:
|
|
|
|
mx = get_mx(input)
|
|
|
|
info['domain_mx'] = mx
|
|
|
|
except:
|
|
|
|
print("MX query failed")
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
whois_data = get_whois(input)
|
|
|
|
info['domain_registrant'] = whois_data.registrant
|
|
|
|
info['domain_nameservers'] = whois_data.name_servers
|
|
|
|
info['domain_registrar'] = whois_data.registrar
|
|
|
|
info['domain_creation'] = whois_data.creation_date
|
|
|
|
info['domain_expiration'] = whois_data.expiration_date
|
|
|
|
except:
|
|
|
|
print("Whois query failed")
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
ipapi = ip_api(ip)
|
|
|
|
info['ip_AS'] = ipapi['as']
|
|
|
|
info['ip_city'] = ipapi['city']
|
|
|
|
info['ip_country'] = ipapi['country']
|
|
|
|
info['ip_is_hosting'] = ipapi['hosting']
|
|
|
|
info['ip_is_mobile'] = ipapi['mobile']
|
|
|
|
info['ip_is_proxy'] = ipapi['proxy']
|
|
|
|
info['ip_reverse'] = ipapi['reverse']
|
|
|
|
info['ip_isp'] = ipapi['isp']
|
|
|
|
info['ip_org'] = ipapi['org']
|
|
|
|
except:
|
|
|
|
print("ip-api.org query failed")
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
hostio = hostio_api(ip, HOSTIO_TOKEN)
|
|
|
|
info['ip_domains'] = hostio['domains']
|
|
|
|
info['ip_domains_count'] = hostio['total']
|
|
|
|
except:
|
|
|
|
print("Host.io query failed")
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
return(info)
|
|
|
|
|
2022-07-17 13:10:03 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host="0.0.0.0")
|