57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
#!/usr/bin/venv python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import whois
|
|
import dns.resolver
|
|
import dns.name
|
|
from config import DNS_QUERIES_TYPE
|
|
|
|
|
|
class DNSInformations:
|
|
def __init__(self, api_key, fqdn):
|
|
self._fqdn = fqdn
|
|
|
|
def whois(self):
|
|
report = dict()
|
|
w = whois.whois(self._fqdn)
|
|
report['domain_name'] = w.domain_name
|
|
report['expiration_date'] = w.expiration_date
|
|
report['creation_date'] = w.creation_date
|
|
report['updated_date'] = w.updated_date
|
|
report['ns'] = w.name_servers
|
|
report['admin_name'] = w.admin_name
|
|
return report
|
|
|
|
def resolver(self):
|
|
report = dict()
|
|
|
|
n = dns.name.from_text(self._fqdn)
|
|
s = self._fqdn.split(".")
|
|
l = len(s)
|
|
fqdn = f"{s[l - 2]}.{s[l - 1]}"
|
|
print(fqdn)
|
|
o = dns.name.from_text(fqdn)
|
|
if n.relativize(o):
|
|
print(True)
|
|
|
|
|
|
for t in DNS_QUERIES_TYPE.keys():
|
|
report[t] = self._resolving(self._fqdn, t, DNS_QUERIES_TYPE[t])
|
|
return report
|
|
|
|
def _resolving(self, fqdn, t, attr):
|
|
report = list()
|
|
res_query = dns.resolver.resolve(fqdn, t)
|
|
for rdata in res_query:
|
|
if isinstance(attr, list):
|
|
data = dict()
|
|
for a in attr:
|
|
data[a] = getattr(rdata, a)
|
|
report.append(data)
|
|
else:
|
|
report.append({
|
|
attr: getattr(rdata, attr)
|
|
})
|
|
return report
|
|
|