Repository navigation
Expand file tree
/
Copy pathurl_reputation_scanner.py
More file actions
106 lines (89 loc) · 3.33 KB
/
Copy pathurl_reputation_scanner.py
File metadata and controls
106 lines (89 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import sys
from datetime import datetime
from urllib.parse import urlparse
# pyrefly: ignore [missing-import]
import dns.resolver
# pyrefly: ignore [missing-import]
import whois
def extract_domain(url):
if not url.startswith('http://') and not url.startswith('https://'):
url = 'http://' + url
parsed_url = urlparse(url)
domain = parsed_url.netloc
if domain.startswith('www.'):
domain = domain[4:]
return domain
def get_domain_age(domain):
try:
w = whois.whois(domain)
creation_date = w.creation_date
if type(creation_date) is list:
creation_date = creation_date[0]
if creation_date:
if isinstance(creation_date, str):
return "Unknown format (string returned)"
if creation_date.tzinfo is not None:
creation_date = creation_date.replace(tzinfo=None)
age = datetime.now() - creation_date
return f"{age.days} days (Created on: {creation_date.strftime('%Y-%m-%d')})"
return "Unknown"
except Exception as e:
return f"Error: {e}"
def get_dns_records(domain, record_type='A'):
try:
answers = dns.resolver.resolve(domain, record_type)
return [rdata.to_text() for rdata in answers]
except dns.resolver.NoAnswer:
return []
except dns.resolver.NXDOMAIN:
return ["Domain does not exist."]
except Exception as e:
return [f"Error: {e}"]
def get_spf_record(domain):
try:
answers = dns.resolver.resolve(domain, 'TXT')
for rdata in answers:
txt_record = rdata.to_text().strip('"')
if "v=spf1" in txt_record:
return txt_record
return "No SPF record found."
except Exception as e:
return f"Error: {e}"
def get_dmarc_record(domain):
dmarc_domain = f"_dmarc.{domain}"
try:
answers = dns.resolver.resolve(dmarc_domain, 'TXT')
for rdata in answers:
txt_record = rdata.to_text().strip('"')
if "v=DMARC1" in txt_record:
return txt_record
return "No DMARC record found."
except Exception as e:
return f"Error: {e}"
def scan_url(url):
print(f"--- URL Reputation Scanner ---")
print(f"Target URL: {url}\n")
domain = extract_domain(url)
print(f"Extracted Domain: {domain}\n")
print("[+] Checking Domain Age...")
age = get_domain_age(domain)
print(f"Age: {age}\n")
print("[+] Checking DNS Records (A, MX, NS)...")
a_records = get_dns_records(domain, 'A')
mx_records = get_dns_records(domain, 'MX')
ns_records = get_dns_records(domain, 'NS')
print(f"A Records: {', '.join(a_records) if a_records else 'None'}")
print(f"MX Records: {', '.join(mx_records) if mx_records else 'None'}")
print(f"NS Records: {', '.join(ns_records) if ns_records else 'None'}\n")
print("[+] Checking SPF Record...")
spf = get_spf_record(domain)
print(f"SPF: {spf}\n")
print("[+] Checking DMARC Record...")
dmarc = get_dmarc_record(domain)
print(f"DMARC: {dmarc}\n")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="URL Reputation Scanner")
parser.add_argument("url", help="The target URL to scan")
args = parser.parse_args()
scan_url(args.url)