|
| 1 | +# # |
| 2 | +# # import imaplib |
| 3 | +# # import getpass |
| 4 | +# # from email import message_from_string |
| 5 | +# # import socket |
| 6 | +# # |
| 7 | +# # import dns.resolver as dnspython |
| 8 | +# # |
| 9 | +# # def get_mx_records(domain): |
| 10 | +# # try: |
| 11 | +# # # Query MX records for the domain |
| 12 | +# # mx_records = dns.resolver.resolve(domain, 'MX') |
| 13 | +# # # Extract and return the MX record data |
| 14 | +# # return [(mx.exchange.to_text(), mx.preference) for mx in mx_records] |
| 15 | +# # except dns.resolver.NoAnswer: |
| 16 | +# # print(f"No MX records found for {domain}") |
| 17 | +# # return [] |
| 18 | +# # except dns.resolver.NXDOMAIN: |
| 19 | +# # print(f"Domain {domain} not found") |
| 20 | +# # return [] |
| 21 | +# # except Exception as e: |
| 22 | +# # print(f"Error: {str(e)}") |
| 23 | +# # return [] |
| 24 | +# # |
| 25 | +# # |
| 26 | +# # # IMAP server settings |
| 27 | +# # imap_server = '' |
| 28 | +# # imap_port = 993 |
| 29 | +# # |
| 30 | +# # # User credentials |
| 31 | +# # email_address = '' |
| 32 | +# # password = '' |
| 33 | +# # |
| 34 | +# # # Connect to the IMAP server |
| 35 | +# # mail = imaplib.IMAP4_SSL(imap_server, imap_port) |
| 36 | +# # |
| 37 | +# # # Log in to the mailbox |
| 38 | +# # mail.login(email_address, password) |
| 39 | +# # |
| 40 | +# # # Select the INBOX |
| 41 | +# # mail.select("inbox") |
| 42 | +# # |
| 43 | +# # # Search for all emails in the INBOX |
| 44 | +# # result, data = mail.search(None, "ALL") |
| 45 | +# # email_ids = data[0].split() |
| 46 | +# # |
| 47 | +# # # Fetch and print header information for each email |
| 48 | +# # for email_id in email_ids: |
| 49 | +# # result, message_data = mail.fetch(email_id, "(BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)])") |
| 50 | +# # raw_email = message_data[0][1].decode('utf-8') |
| 51 | +# # msg = message_from_string(raw_email) |
| 52 | +# # FromDomain = msg['From'].split('@')[1].rstrip('>') |
| 53 | +# # MailServer = get_mx_records(FromDomain) |
| 54 | +# # print(f'From Domain {FromDomain}') |
| 55 | +# # print(f'MX Records of the domains {MailServer}') |
| 56 | +# # print(f'Mail Server From Domain {MailServer}') |
| 57 | +# # print(f"Email ID: {email_id}") |
| 58 | +# # print(f"From: {msg['From']}") |
| 59 | +# # print(f"To: {msg['To']}") |
| 60 | +# # print(f"Subject: {msg['Subject']}") |
| 61 | +# # print(f"Date: {msg['Date']}") |
| 62 | +# # print("-" * 30) |
| 63 | +# # print(message_data) |
| 64 | +# # |
| 65 | +# # # Logout |
| 66 | +# # mail.logout() |
| 67 | +# # # |
| 68 | +# # # # from cryptography import x509 |
| 69 | +# # # # from cryptography.hazmat.backends import default_backend |
| 70 | +# # # # |
| 71 | +# # # # def get_domains_covered(cert_path): |
| 72 | +# # # # with open(cert_path, 'rb') as cert_file: |
| 73 | +# # # # cert_data = cert_file.read() |
| 74 | +# # # # cert = x509.load_pem_x509_certificate(cert_data, default_backend()) |
| 75 | +# # # # |
| 76 | +# # # # # Check for the Subject Alternative Name (SAN) extension |
| 77 | +# # # # san_extension = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName) |
| 78 | +# # # # |
| 79 | +# # # # if san_extension: |
| 80 | +# # # # # Extract and print the domains from SAN |
| 81 | +# # # # san_domains = san_extension.value.get_values_for_type(x509.DNSName) |
| 82 | +# # # # return san_domains |
| 83 | +# # # # else: |
| 84 | +# # # # # If SAN is not present, return the Common Name as a fallback |
| 85 | +# # # # return [cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value] |
| 86 | +# # # # |
| 87 | +# # # # # Example usage |
| 88 | +# # # # cert_path = '/etc/letsencrypt/live/cyberplanner.io/fullchain.pem' |
| 89 | +# # # # domains_covered = get_domains_covered(cert_path) |
| 90 | +# # # # |
| 91 | +# # # # print("Domains covered by the certificate:") |
| 92 | +# # # # for domain in domains_covered: |
| 93 | +# # # # print(domain) |
1 | 94 | # |
2 | | -# import imaplib |
3 | | -# import getpass |
4 | | -# from email import message_from_string |
5 | | -# import socket |
| 95 | +# import dns.resolver |
6 | 96 | # |
7 | | -# import dns.resolver as dnspython |
8 | 97 | # |
9 | | -# def get_mx_records(domain): |
| 98 | +# def query_sbl(ip): |
10 | 99 | # try: |
11 | | -# # Query MX records for the domain |
12 | | -# mx_records = dns.resolver.resolve(domain, 'MX') |
13 | | -# # Extract and return the MX record data |
14 | | -# return [(mx.exchange.to_text(), mx.preference) for mx in mx_records] |
15 | | -# except dns.resolver.NoAnswer: |
16 | | -# print(f"No MX records found for {domain}") |
17 | | -# return [] |
18 | | -# except dns.resolver.NXDOMAIN: |
19 | | -# print(f"Domain {domain} not found") |
20 | | -# return [] |
21 | | -# except Exception as e: |
22 | | -# print(f"Error: {str(e)}") |
23 | | -# return [] |
24 | | -# |
25 | | -# |
26 | | -# # IMAP server settings |
27 | | -# imap_server = '' |
28 | | -# imap_port = 993 |
| 100 | +# # Construct the reverse DNS lookup domain |
| 101 | +# reversed_ip = '.'.join(reversed(ip.split('.'))) |
| 102 | +# sbl_domain = reversed_ip + '.zen.spamhaus.org' |
29 | 103 | # |
30 | | -# # User credentials |
31 | | -# email_address = '' |
32 | | -# password = '' |
| 104 | +# # Query the SBL DNS server |
| 105 | +# result = dns.resolver.resolve(sbl_domain, 'A') |
33 | 106 | # |
34 | | -# # Connect to the IMAP server |
35 | | -# mail = imaplib.IMAP4_SSL(imap_server, imap_port) |
36 | | -# |
37 | | -# # Log in to the mailbox |
38 | | -# mail.login(email_address, password) |
| 107 | +# # If the query returns a result, it means the IP is listed in SBL |
| 108 | +# return True |
| 109 | +# except dns.resolver.NXDOMAIN: |
| 110 | +# # If the domain does not exist, the IP is not listed in SBL |
| 111 | +# return False |
| 112 | +# except dns.resolver.Timeout: |
| 113 | +# # Handle DNS query timeout |
| 114 | +# print("DNS query timed out") |
| 115 | +# return None |
| 116 | +# except dns.resolver.NoAnswer: |
| 117 | +# # Handle no DNS answer |
| 118 | +# print("No DNS answer") |
39 | 119 | # |
40 | | -# # Select the INBOX |
41 | | -# mail.select("inbox") |
| 120 | +# return None |
42 | 121 | # |
43 | | -# # Search for all emails in the INBOX |
44 | | -# result, data = mail.search(None, "ALL") |
45 | | -# email_ids = data[0].split() |
46 | 122 | # |
47 | | -# # Fetch and print header information for each email |
48 | | -# for email_id in email_ids: |
49 | | -# result, message_data = mail.fetch(email_id, "(BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)])") |
50 | | -# raw_email = message_data[0][1].decode('utf-8') |
51 | | -# msg = message_from_string(raw_email) |
52 | | -# FromDomain = msg['From'].split('@')[1].rstrip('>') |
53 | | -# MailServer = get_mx_records(FromDomain) |
54 | | -# print(f'From Domain {FromDomain}') |
55 | | -# print(f'MX Records of the domains {MailServer}') |
56 | | -# print(f'Mail Server From Domain {MailServer}') |
57 | | -# print(f"Email ID: {email_id}") |
58 | | -# print(f"From: {msg['From']}") |
59 | | -# print(f"To: {msg['To']}") |
60 | | -# print(f"Subject: {msg['Subject']}") |
61 | | -# print(f"Date: {msg['Date']}") |
62 | | -# print("-" * 30) |
63 | | -# print(message_data) |
| 123 | +# # Example usage |
| 124 | +# ip_to_check = '209.85.166.5' |
| 125 | +# result = query_sbl(ip_to_check) |
| 126 | +# if result is True: |
| 127 | +# print(f"The IP {ip_to_check} is listed in Spamhaus Block List (SBL)") |
| 128 | +# elif result is False: |
| 129 | +# print(f"The IP {ip_to_check} is not listed in Spamhaus Block List (SBL)") |
| 130 | +# else: |
| 131 | +# print("Unable to determine SBL status for the given IP") |
64 | 132 | # |
65 | | -# # Logout |
66 | | -# mail.logout() |
67 | | -# # |
68 | | -# # # from cryptography import x509 |
69 | | -# # # from cryptography.hazmat.backends import default_backend |
70 | | -# # # |
71 | | -# # # def get_domains_covered(cert_path): |
72 | | -# # # with open(cert_path, 'rb') as cert_file: |
73 | | -# # # cert_data = cert_file.read() |
74 | | -# # # cert = x509.load_pem_x509_certificate(cert_data, default_backend()) |
75 | | -# # # |
76 | | -# # # # Check for the Subject Alternative Name (SAN) extension |
77 | | -# # # san_extension = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName) |
78 | | -# # # |
79 | | -# # # if san_extension: |
80 | | -# # # # Extract and print the domains from SAN |
81 | | -# # # san_domains = san_extension.value.get_values_for_type(x509.DNSName) |
82 | | -# # # return san_domains |
83 | | -# # # else: |
84 | | -# # # # If SAN is not present, return the Common Name as a fallback |
85 | | -# # # return [cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value] |
86 | | -# # # |
87 | | -# # # # Example usage |
88 | | -# # # cert_path = '/etc/letsencrypt/live/cyberplanner.io/fullchain.pem' |
89 | | -# # # domains_covered = get_domains_covered(cert_path) |
90 | | -# # # |
91 | | -# # # print("Domains covered by the certificate:") |
92 | | -# # # for domain in domains_covered: |
93 | | -# # # print(domain) |
|
0 commit comments