Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def start_dnscan(domain):
resolver = aiodns.DNSResolver()
loop = asyncio.get_event_loop()
tasks = list()
tasks.append(loop.create_task(resolve(domain_to_brute, 'NS')))
tasks.append(loop.create_task(resolve(domain_to_brute, 'MX')))
loop.run_until_complete(asyncio.wait(tasks))
futures = list()
for t in tasks:
for domain_name in t.result():
name = resolver.query(domain_name, 'A')
name.add_done_callback(error_checker_callback)
name.data = domain_name
futures.append(name)
result = loop.run_until_complete(asyncio.wait(futures))
def setUp(self) -> None:
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.loop.set_debug(True)
self.timeout = int(os.environ.get('ASYNC_TIMEOUT', '5'))
self.timeout_handle = self.loop.call_later(
self.timeout, self.on_timeout)
self.normalizer = email_normalize.Normalizer()
self.resolver = aiodns.DNSResolver(loop=self.loop)
self.normalizer._resolver = self.resolver
print('Invalid infohash.')
exit(1)
nodes = SortedQueue(args.infohash)
logger = logging.getLogger('ih2torrent')
handler = StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s][%(levelname)s] %(message)s')
handler.setFormatter(formatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
try:
loop = asyncio.get_event_loop()
resolver = aiodns.DNSResolver(loop=loop)
loop.run_until_complete(ih2torrent(loop, args.infohash, args.file, args.bootstrap))
except KeyboardInterrupt:
print()
print('Letting the remaining tasks finish before termination.')
except Exception as e:
print('Unexpected error:', e)
pending = asyncio.Task.all_tasks()
for task in pending:
task.cancel()
try:
loop.run_until_complete(asyncio.gather(*pending))
except CancelledError:
pass
loop.close()
async def validate_email(email, loop):
"""
check an email is likely to exist
could do SMTP looks ups: https://gist.github.com/samuelcolvin/3652427c07fac775d0cdc8af127c0ed1
but not really worth it
"""
domain = email.split('@', 1)[1]
resolver = aiodns.DNSResolver(loop=loop)
try:
with timeout(2, loop=loop):
await resolver.query(domain, 'MX')
except (aiodns.error.DNSError, ValueError, asyncio.TimeoutError) as e:
logger.info('looking up "%s": error %s %s', email, e.__class__.__name__, e)
return False
else:
return True
async def get_mx_ip(hostname):
'''Get MX record by hostname.
'''
if hostname not in MX_DNS_CACHE:
try:
resolver = aiodns.DNSResolver()
MX_DNS_CACHE[hostname] = await resolver.query(hostname, 'MX')
except aiodns.error.DNSError as e:
MX_DNS_CACHE[hostname] = None
return MX_DNS_CACHE[hostname]
def dns_resolve(self):
padding_domain = 'www.' + self.domain
# loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
resolver = aiodns.DNSResolver(loop=loop)
f = resolver.query(padding_domain, 'A')
result = loop.run_until_complete(f)
return result[0].host
def __init__(self, loop):
self.dnsResolver = aiodns.DNSResolver(loop=loop)
def __init__(self, timeout=5, loop=None):
self._timeout = timeout
self._loop = loop or asyncio.get_event_loop()
self._resolver = aiodns.DNSResolver(loop=self._loop)
}
self.options = {
}
# ~ queue object
self.word_count = int(self.json_entry['args'].raw_depth)
self.word_list_queue = queue.Queue(maxsize=0)
self.tasks = []
self.domain = ''
self.errors = []
self.fqdn = []
self.sub_gen_count = 0
# disable uvloop until supports windows
# asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
self.loop = asyncio.get_event_loop()
self.resolver = aiodns.DNSResolver(loop=self.loop, rotate=True)
# TODO: make max tasks defined in config.json
self.max_tasks = 1024
# TODO: make total set from wordcount in config.json
self.sem = asyncio.BoundedSemaphore(self.max_tasks)
self.cs = core_scrub.Scrub()
self.core_args = self.json_entry['args']
self.core_resolvers = self.json_entry['resolvers']
self.silent = self.json_entry['silent']