minor changes

This commit is contained in:
Joost Agterhoek 2025-06-10 21:04:43 +02:00
parent b193999667
commit 1633b975c3
3 changed files with 27 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import validators
from ipwhois import IPWhois from ipwhois import IPWhois
from whois import whois from whois import whois
from .constants import DOMAIN, EMAIL, IPV4, IPV6, URL from .constants import DOMAIN, EMAIL, IPV4, IPV6, URL
from datetime import datetime
def determine(host): def determine(host):
@ -25,9 +26,11 @@ def determine(host):
def domain(host): def domain(host):
result = dict(whois(host)) info = dict(whois(host))
if type(result["domain_name"]) is list: if type(info["domain_name"]) is list:
result["domain_name"] = result["domain_name"][0] info["domain_name"] = info["domain_name"][0]
selection = {"registrar_country", "registrar"}
result = {key: info.get(key) for key in selection}
return result return result

View File

@ -17,12 +17,21 @@ from . import host_data
import tldextract import tldextract
class Test(object):
def __init__(self):
self.host = "joostagterhoek.nl"
self.host_type = "domain"
self.vt = {"whatever": "whatever", "second_key": 4}
self.email_security = ["1", 1, "2", "3"]
class Lookedup(object): class Lookedup(object):
def __init__(self, host): def __init__(self, host):
self.host = host self.host = host
self.host_type = determine(self.host) self.host_type = determine(self.host)
self = self.specific() self = self.specific()
# TODO: consolidate all below functions if possible # TODO: consolidate all below functions if possible
# Implement an __eq__ method based on host name: https://dnmtechs.com/comparing-object-instances-by-attributes-in-python-3-a-comprehensive-guide/
def url_lookup(self): def url_lookup(self):
self.domain = urlparse(self.host).netloc self.domain = urlparse(self.host).netloc
@ -46,7 +55,8 @@ class Lookedup(object):
self.metadata = domain(self.host) self.metadata = domain(self.host)
self.domain = self.metadata["domain_name"] self.domain = self.metadata["domain_name"]
self.email_security = spf_dmarc(self.domain) self.email_security = spf_dmarc(self.domain)
self.vt, self.vt_dict = virustotal_api.analyse2(self.host, self.host_type) # self.vt, self.vt_dict = virustotal_api.analyse2(self.host, self.host_type)
self.vt = virustotal_api.analyse2(self.host, self.host_type)
self.abuseipdb = abuseipdb_api.analyse(self.ip_address) self.abuseipdb = abuseipdb_api.analyse(self.ip_address)
return self return self
@ -127,18 +137,25 @@ def extract(user_input):
hosts.append(item) hosts.append(item)
else: else:
errors.append(item) errors.append(item)
print(hosts)
print(errors)
return hosts, errors return hosts, errors
def domain(host): def domain(host):
result = dict(whois(host)) result = dict(whois(host))
print("RESULT IS: ", result)
if type(result["creation_date"]) is list: if type(result["creation_date"]) is list:
result["creation_date"] = result["creation_date"][0].strftime("%d-%m-%Y") result["creation_date"] = result["creation_date"][0].strftime("%d-%m-%Y")
else: else:
result["creation_date"] = result["creation_date"].strftime("%d-%m-%Y") result["creation_date"] = result["creation_date"].strftime("%d-%m-%Y")
if type(result["domain_name"]) is list: if type(result["domain_name"]) is list:
result["domain_name"] = result["domain_name"][0] result["domain_name"] = result["domain_name"][0]
return result # result["creation_date"] = result["creation_date"].isoformat()
included = {"domain_name", "creation_date", "registrar", "registrar_country"}
filtered = {key: value for key, value in result.items() if key in included}
print("FILTERED IS: ", filtered)
return filtered
def spf_dmarc(domain): def spf_dmarc(domain):

View File

@ -108,4 +108,5 @@ def analyse2(host, host_type):
"%d-%m-%Y", "%d-%m-%Y",
time.gmtime(last_update), time.gmtime(last_update),
) )
return summary, analysis_json # return summary, analysis_json
return summary