-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e231dcd
commit a9b7537
Showing
4 changed files
with
147 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import json | ||
import os | ||
import sys | ||
import asyncio | ||
import aiofiles | ||
import dns.asyncresolver | ||
from datetime import datetime | ||
|
||
resolver = dns.asyncresolver.Resolver() | ||
resolver.nameservers = ['8.8.8.8', '8.8.4.4'] | ||
|
||
async def get_a_records(domain, retries=3, delay=1): | ||
for attempt in range(retries): | ||
try: | ||
answer = await resolver.resolve(domain, 'A') | ||
return domain, " ".join([rdata.to_text() for rdata in answer]) | ||
except (dns.resolver.NoAnswer, dns.resolver.NXDOMAIN) as e: | ||
return domain, f"Error: {str(e)}" | ||
except Exception as e: | ||
if attempt < retries - 1: | ||
await asyncio.sleep(delay) | ||
else: | ||
return domain, f"Error: {str(e)}" | ||
|
||
async def process_domain(domain, results): | ||
domain, a_records = await get_a_records(domain) | ||
if a_records and "Error" not in a_records: | ||
results.append({"hostname": domain, "ip": a_records.split()[0]}) | ||
print(f"\r{domain} -> {a_records}", end="") | ||
|
||
async def main(): | ||
tasks = [] | ||
results = [] | ||
max_concurrent_tasks = 1000 | ||
semaphore = asyncio.Semaphore(max_concurrent_tasks) | ||
|
||
async def limited_task(domain): | ||
async with semaphore: | ||
await process_domain(domain, results) | ||
|
||
# Read the list of domains from the file | ||
try: | ||
async with aiofiles.open('./base-domain-list.txt', 'r') as f: | ||
domains = await f.readlines() | ||
except FileNotFoundError: | ||
print("Domain list file not found.") | ||
sys.exit(1) | ||
|
||
domains = [domain.strip() for domain in domains] # Clean up line breaks | ||
|
||
for domain in domains: | ||
tasks.append(limited_task(domain)) | ||
|
||
await asyncio.gather(*tasks) | ||
|
||
if len(results) == 0: | ||
print("\nNo results found.") | ||
return | ||
|
||
# Display results instead of saving them | ||
async with aiofiles.open('./base-ip-list.txt', 'w') as f: | ||
await f.write("\n".join(map(lambda a: a["ip"], results)) + "\n") | ||
|
||
async with aiofiles.open('./amnezia-base-list.json', 'w') as f: | ||
await f.write(json.dumps(results, indent=4)) | ||
|
||
if __name__ == "__main__": | ||
start_time = datetime.now() | ||
asyncio.run(main()) | ||
end_time = datetime.now() | ||
print(f"\nFinished! Time taken: {end_time - start_time}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import json | ||
import asyncio | ||
import aiofiles | ||
from datetime import datetime | ||
import os | ||
|
||
async def append_to_json(file_path, new_data): | ||
# Check if the file exists and create if not | ||
if not os.path.exists(file_path): | ||
async with aiofiles.open(file_path, 'w') as f: | ||
await f.write(json.dumps([], indent=4)) | ||
|
||
# Read and update the existing data | ||
async with aiofiles.open(file_path, 'r') as f: | ||
try: | ||
existing_data = json.loads(await f.read()) | ||
except json.JSONDecodeError: | ||
existing_data = [] # In case of empty or invalid JSON | ||
|
||
existing_data.extend(new_data) # Efficiently append new data | ||
|
||
# Write the updated data back to the file | ||
async with aiofiles.open(file_path, 'w') as f: | ||
await f.write(json.dumps(existing_data, indent=4)) | ||
|
||
|
||
async def process_region(region: str): | ||
try: | ||
region_file_path = os.path.join("regions", region, f'amnezia-{region}-voice-list.json') | ||
async with aiofiles.open(region_file_path, 'r') as f: | ||
return json.loads(await f.read()) | ||
except Exception as e: | ||
print(f"Error processing region {region}: {e}") | ||
return [] # Return empty list on failure | ||
|
||
|
||
async def main(): | ||
regions = os.listdir("regions") | ||
data = [] | ||
|
||
# Process regions concurrently | ||
tasks = [process_region(region) for region in regions] | ||
region_data = await asyncio.gather(*tasks) | ||
|
||
for row in region_data: | ||
if row: | ||
data.extend(row) | ||
|
||
# Write to text files | ||
ip_list = "\n".join([voice["ip"] for voice in data]) | ||
domain_list = "\n".join([voice["hostname"] for voice in data]) | ||
|
||
async with aiofiles.open('voice-ip-list.txt', 'w') as f: | ||
await f.write(ip_list + "\n") | ||
|
||
async with aiofiles.open('voice-domain-list.txt', 'w') as f: | ||
await f.write(domain_list + "\n") | ||
|
||
# Append new data to the JSON file | ||
await append_to_json('amnezia-voice-list.json', data) | ||
|
||
|
||
if __name__ == "__main__": | ||
start_time = datetime.now() | ||
asyncio.run(main()) | ||
end_time = datetime.now() | ||
print(f"\nFinished! Time taken: {end_time - start_time}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters