corrected wrong import and added generic lookup module

This commit is contained in:
Joost Agterhoek 2024-08-14 15:34:48 +02:00
parent ac7c059d34
commit d562b238c2
14 changed files with 85 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
generic/domain_lookup.py Normal file
View File

@ -0,0 +1,5 @@
import socket
def get_ip_address(domain):
hostname = socket.gethostbyname(domain)
return hostname

5
generic/ip_lookup.py Normal file
View File

@ -0,0 +1,5 @@
import socket
def get_hostname(IP):
hostname = socket.gethostbyaddr(IP)
return hostname

7
generic/sanitize.py Normal file
View File

@ -0,0 +1,7 @@
import re
def strip_and_list(hosts):
if hosts.strip() != '':
sanitized = re.split("; |, | |\n", hosts)
return sanitized
# break

19
generic/spf_dmarc.py Normal file
View File

@ -0,0 +1,19 @@
from checkdmarc.dmarc import check_dmarc
from checkdmarc.spf import check_spf
import validators
def extract_domain(host: str) -> str:
if validators.email(host):
host = host.split('@')[1]
return host
def lookup(host: str) -> tuple:
host = extract_domain(host)
result_dmarc = check_dmarc(host)
dmarc_quarantine = result_dmarc['record'].split(';')[1]
result_spf = check_spf(host)
# spf_includes = result_spf['record'].split()[1:]
spf_includes = ', '.join(str(item) for item in result_spf['record'].split()[1:])
return (dmarc_quarantine, spf_includes)

View File

@ -0,0 +1,8 @@
import validators
def type_hosts(hosts):
validated_hosts = []
for host in hosts:
if validators.url(host) or validators.domain(host) or validators.ipv4(host) or validators.ipv6(host) or validators.email(host):
validated_hosts.append(host)
return validated_hosts

View File

@ -0,0 +1,38 @@
import validators
def normalize(host):
domain_name, tld = "", ""
if host.startswith('www.'):
domain_name, tld = str.split(host,'.')[-2:]
normalized_domain = domain_name + '.' + tld
return normalized_domain
else:
return host
def type_hosts(hosts):
validated_hosts = {
"URLs": [],
"domains": [],
"IPs": [],
"emails": [],
}
URLs = []
domains = []
IPs = []
email = []
for host in hosts:
if validators.url(host):
URLs.append(host)
elif validators.domain(host):
domains.append(normalize(host))
elif validators.ipv4(host) or validators.ipv6(host):
IPs.append(host)
elif validators.email(host):
email.append(host)
else:
print("This is not a URL, IP, email address or hostname: ", host)
validated_hosts["URLs"].extend([i for i in URLs])
validated_hosts["domains"].extend([i for i in domains])
validated_hosts["IPs"].extend([i for i in IPs])
validated_hosts["emails"].extend([i for i in email])
return validated_hosts

View File

@ -1,14 +1,15 @@
# From: https://www.geeksforgeeks.org/how-to-bind-the-enter-key-to-a-tkinter-window/
# From: https://www.geeksforgeeks.org/how-to-bind-the-enter-key-to-a-t//kinter-window/
# importing tkinter
import tkinter as tk
from ..generic import sanitize, type_hosts_listed, type_hosts_organized, ip_lookup, domain_lookup, spf_dmarc
from generic import sanitize, type_hosts_listed, type_hosts_organized, ip_lookup, domain_lookup, spf_dmarc
# function to run on pressing
# 'ENTER' key from keyboard.
def key_handler_function(event):
inputs = entry.get()
print(type(inputs))
sanitized = sanitize.strip_and_list(inputs)
typed = type_hosts_listed.type_hosts(sanitized)
textbox.insert('end', typed)