-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IP blacklists #59
Labels
enhancement
New feature or request
Milestone
Comments
required: ip_addresses.txt (combined and sanitized from selected sources) ip2fqdn.yml
dns_resolver.py
|
Here’s an enhanced version of the script with progress reporting and further improvements: Enhanced Python Scriptimport asyncio
import concurrent.futures
import dns.resolver
import dns.reversename
import logging
from tqdm import tqdm
# Setup logging
logging.basicConfig(filename='resolved_ips.log', level=logging.INFO)
def load_from_file(filename):
"""Load lines from a file and return them as a list."""
try:
with open(filename, 'r') as file:
return [line.strip() for line in file if line.strip()]
except FileNotFoundError:
logging.error(f"{filename} not found.")
return []
async def resolve_ip(ip, dns_server):
"""Resolve IP using the provided DNS server and log the result."""
loop = asyncio.get_running_loop()
resolver = dns.resolver.Resolver()
resolver.nameservers = [dns_server]
resolver.timeout = timeout
resolver.lifetime = timeout
try:
rev_name = dns.reversename.from_address(ip)
with concurrent.futures.ThreadPoolExecutor() as executor:
resolved = await loop.run_in_executor(executor, lambda: str(resolver.resolve(rev_name, "PTR")[0]))
logging.info(f"{ip} resolves to {resolved} using DNS server {dns_server}")
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
# Ignore IPs with no resolution or if a timeout occurs
pass
async def main():
# Load IP addresses and DNS servers from files
ip_addresses = load_from_file('ips.txt')
dns_servers = load_from_file('dns_servers.txt')
if not ip_addresses or not dns_servers:
logging.error("IP addresses or DNS servers are missing.")
return
# Divide IPs among DNS servers
ips_per_server = len(ip_addresses) // len(dns_servers)
if len(ip_addresses) % len(dns_servers) != 0:
ips_per_server += 1
tasks = []
for i in range(len(dns_servers)):
start_index = i * ips_per_server
end_index = start_index + ips_per_server
for ip in ip_addresses[start_index:end_index]:
tasks.append(resolve_ip(ip, dns_servers[i]))
# Run tasks with progress bar
for _ in tqdm(asyncio.as_completed(tasks), total=len(tasks), desc='Resolving IPs'):
pass
# Set the timeout for DNS queries
timeout = 1.0
# Run the main coroutine
asyncio.run(main()) Instructions
Explanation
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: