diff --git a/generic/__pycache__/domain_lookup.cpython-312.pyc b/generic/__pycache__/domain_lookup.cpython-312.pyc new file mode 100644 index 0000000..383727c Binary files /dev/null and b/generic/__pycache__/domain_lookup.cpython-312.pyc differ diff --git a/generic/__pycache__/ip_lookup.cpython-312.pyc b/generic/__pycache__/ip_lookup.cpython-312.pyc new file mode 100644 index 0000000..fae8203 Binary files /dev/null and b/generic/__pycache__/ip_lookup.cpython-312.pyc differ diff --git a/generic/__pycache__/sanitize.cpython-312.pyc b/generic/__pycache__/sanitize.cpython-312.pyc new file mode 100644 index 0000000..81b4c28 Binary files /dev/null and b/generic/__pycache__/sanitize.cpython-312.pyc differ diff --git a/generic/__pycache__/spf_dmarc.cpython-312.pyc b/generic/__pycache__/spf_dmarc.cpython-312.pyc new file mode 100644 index 0000000..02d1dc0 Binary files /dev/null and b/generic/__pycache__/spf_dmarc.cpython-312.pyc differ diff --git a/generic/__pycache__/type_hosts.cpython-312.pyc b/generic/__pycache__/type_hosts.cpython-312.pyc new file mode 100644 index 0000000..dfee58d Binary files /dev/null and b/generic/__pycache__/type_hosts.cpython-312.pyc differ diff --git a/generic/__pycache__/type_hosts_listed.cpython-312.pyc b/generic/__pycache__/type_hosts_listed.cpython-312.pyc new file mode 100644 index 0000000..adf095c Binary files /dev/null and b/generic/__pycache__/type_hosts_listed.cpython-312.pyc differ diff --git a/generic/__pycache__/type_hosts_organized.cpython-312.pyc b/generic/__pycache__/type_hosts_organized.cpython-312.pyc new file mode 100644 index 0000000..5855079 Binary files /dev/null and b/generic/__pycache__/type_hosts_organized.cpython-312.pyc differ diff --git a/generic/domain_lookup.py b/generic/domain_lookup.py new file mode 100644 index 0000000..251d54b --- /dev/null +++ b/generic/domain_lookup.py @@ -0,0 +1,5 @@ +import socket + +def get_ip_address(domain): + hostname = socket.gethostbyname(domain) + return hostname diff --git a/generic/ip_lookup.py b/generic/ip_lookup.py new file mode 100644 index 0000000..a2b6ca5 --- /dev/null +++ b/generic/ip_lookup.py @@ -0,0 +1,5 @@ +import socket + +def get_hostname(IP): + hostname = socket.gethostbyaddr(IP) + return hostname diff --git a/generic/sanitize.py b/generic/sanitize.py new file mode 100644 index 0000000..5da7c76 --- /dev/null +++ b/generic/sanitize.py @@ -0,0 +1,7 @@ +import re + +def strip_and_list(hosts): + if hosts.strip() != '': + sanitized = re.split("; |, | |\n", hosts) + return sanitized + # break diff --git a/generic/spf_dmarc.py b/generic/spf_dmarc.py new file mode 100644 index 0000000..f310eff --- /dev/null +++ b/generic/spf_dmarc.py @@ -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) + diff --git a/generic/type_hosts_listed.py b/generic/type_hosts_listed.py new file mode 100644 index 0000000..0ca4cf2 --- /dev/null +++ b/generic/type_hosts_listed.py @@ -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 diff --git a/generic/type_hosts_organized.py b/generic/type_hosts_organized.py new file mode 100644 index 0000000..27b88f1 --- /dev/null +++ b/generic/type_hosts_organized.py @@ -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 diff --git a/tkinter-enter.py b/tkinter-enter.py index 022f1bb..e632782 100644 --- a/tkinter-enter.py +++ b/tkinter-enter.py @@ -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)