Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import subprocess
- import re
- import os
- import dns.resolver
- import ipaddress
- from ipwhois import IPWhois
- from reportlab.lib.pagesizes import letter
- from reportlab.pdfgen import canvas
- from datetime import datetime
- from concurrent.futures import ThreadPoolExecutor, as_completed
- def main():
- # Define the nameserver you want to query
- NAMESERVER = "ns3.my-ndns.com"
- # Fetch domains associated with the nameserver using curl
- url = f"https:/dns.coffee/api/nameservers/{NAMESERVER}"
- output_file = "coffee.txt"
- print(f"Fetching domains associated with nameserver: {NAMESERVER}")
- # Execute the curl command
- curl_command = ["curl", url, "-o", output_file]
- try:
- subprocess.run(curl_command, check=True)
- except subprocess.CalledProcessError as e:
- print(f"Error fetching data from {url}: {e}")
- return
- # Read the content of coffee.txt
- with open(output_file, 'r') as f:
- content = f.read()
- # Extract domain names from the JSON response using regular expressions
- domains = re.findall(r'"name":\s*"([^"]+)"', content)
- # Remove duplicates and empty lines
- domains = list(set(domain.strip() for domain in domains if domain.strip()))
- # Exclude known domains if you have a list
- known_domains = set()
- if os.path.exists('known.txt'):
- with open('known.txt', 'r') as f:
- known_domains = set(line.strip() for line in f if line.strip())
- domains = [domain for domain in domains if domain not in known_domains]
- print("Processing domains...")
- # Prepare dictionary to store information
- ip_info = {}
- # Use ThreadPoolExecutor for concurrency
- max_workers = 10 # Adjust based on your system's capabilities
- with ThreadPoolExecutor(max_workers=max_workers) as executor:
- # Submit tasks to the executor
- future_to_domain = {executor.submit(process_domain, domain): domain for domain in domains}
- for future in as_completed(future_to_domain):
- domain = future_to_domain[future]
- try:
- info = future.result()
- ip_info[domain] = info
- except Exception as e:
- print(f"Error processing domain {domain}: {e}")
- ip_info[domain] = {'ip': 'Error', 'as_owner': 'Error'}
- # Save IP information to a file
- ip_output_filename = "Domain_IP_AS_Info.txt"
- with open(ip_output_filename, 'w') as f:
- for domain, info in ip_info.items():
- ip = info.get('ip', 'N/A')
- as_owner = info.get('as_owner', 'N/A')
- f.write(f"{domain}: IP: {ip}, AS: {as_owner}\n")
- print(f"Domain IP and AS information saved in {ip_output_filename}")
- # Generate intelligence report PDF for specific AS Owners
- print("Generating intelligence report for specified domains...")
- generate_pdf_report(ip_info)
- print("Intelligence report generated as 'Intel_Report.pdf'")
- def process_domain(domain):
- try:
- # Use a specific DNS resolver
- resolver = dns.resolver.Resolver()
- resolver.nameservers = ['1.1.1.1'] # Cloudflare's DNS resolver
- answers = resolver.resolve(domain, 'A')
- ip_address = answers[0].to_text()
- # Validate the IP address
- try:
- ip_address_obj = ipaddress.ip_address(ip_address)
- except ValueError:
- print(f"{domain} resolves to an invalid IP address {ip_address}.")
- return {'ip': 'Invalid IP', 'as_owner': 'N/A'}
- # Check if the IP is public
- if not ip_address_obj.is_global:
- print(f"{domain} resolves to a non-public IP address {ip_address}. Skipping RDAP lookup.")
- return {'ip': ip_address, 'as_owner': 'Reserved or Private IP'}
- # Get AS information without connecting to the domain
- obj = IPWhois(ip_address)
- results = obj.lookup_rdap(depth=1)
- asn_description = results.get('asn_description', 'Unknown')
- print(f"{domain} resolves to IP {ip_address}, AS: {asn_description}")
- return {'ip': ip_address, 'as_owner': asn_description}
- except dns.resolver.NoAnswer:
- print(f"No DNS answer for domain {domain}.")
- return {'ip': 'No Answer', 'as_owner': 'N/A'}
- except dns.resolver.NXDOMAIN:
- print(f"Domain {domain} does not exist.")
- return {'ip': 'NXDOMAIN', 'as_owner': 'N/A'}
- except dns.exception.Timeout:
- print(f"DNS query for domain {domain} timed out.")
- return {'ip': 'Timeout', 'as_owner': 'N/A'}
- except Exception as e:
- print(f"Error processing domain {domain}: {e}")
- return {'ip': 'Error', 'as_owner': 'Error'}
- def generate_pdf_report(ip_info):
- pdf_filename = "Intel_Report.pdf"
- c = canvas.Canvas(pdf_filename, pagesize=letter)
- width, height = letter
- c.setFont("Helvetica", 12)
- y = height - 50 # Start from top of the page
- # Report Title
- c.setFont("Helvetica-Bold", 16)
- c.drawString(50, y, "Intelligence Report")
- y -= 30
- c.setFont("Helvetica", 12)
- c.drawString(50, y, f"Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
- y -= 40
- # Adjusted keywords to include variations
- keywords = ['digitalocean', 'virtuo']
- # Filter ip_info to include domains with AS Owners containing the keywords
- filtered_ip_info = {}
- for domain, info in ip_info.items():
- as_owner_clean = info.get('as_owner', '').replace(' ', '').lower()
- if any(keyword.replace(' ', '') in as_owner_clean for keyword in keywords):
- filtered_ip_info[domain] = info
- if not filtered_ip_info:
- c.drawString(50, y, "No domains found with specified AS Owners.")
- else:
- for domain, info in filtered_ip_info.items():
- if y < 100:
- c.showPage()
- y = height - 50
- ip = info.get('ip', 'N/A')
- as_owner = info.get('as_owner', 'N/A')
- c.setFont("Helvetica-Bold", 14)
- c.drawString(50, y, f"Domain: {domain}")
- y -= 20
- c.setFont("Helvetica", 12)
- c.drawString(70, y, f"IP Address: {ip}")
- y -= 15
- c.drawString(70, y, f"AS Owner: {as_owner}")
- y -= 30 # Space before next domain
- c.save()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment