# Path: theHarvester/lib/hostchecker.py
# class Checker:
#     def __init__(self, hosts: list, nameserver=False):
#     async def query(host, resolver) -> Tuple[str, Any]:
#     async def query_all(self, resolver) -> list:
#     async def check(self):


import re
import sys
from aiodns import DNSResolver
from ipaddress import IPv4Network
from typing import Callable, List, Optional
from theHarvester.lib import hostchecker
#####################################################################
# DNS FORCE
#####################################################################


class DnsForce:

    def __init__(self, domain, dnsserver, verbose=False):
        self.domain = domain
        self.subdo = False
        self.verbose = verbose
        # self.dnsserver = [dnsserver] if isinstance(dnsserver, str) else dnsserver
        self.dnsserver = list(map(str, dnsserver.split(','))) if isinstance(dnsserver, str) else dnsserver
        try:
            with open('/etc/theHarvester/wordlists/dns-names.txt', 'r') as file:
                self.list = file.readlines()
        except FileNotFoundError:
            try:
                with open('/usr/local/etc/theHarvester/wordlists/dns-names.txt', 'r') as file:
                    self.list = file.readlines()
            except FileNotFoundError:
                with open('wordlists/dns-names.txt', 'r') as file:
                    self.list = file.readlines()
        self.domain = domain.replace('www.', '')
        self.list = [f'{word.strip()}.{self.domain}' for word in self.list]

    async def run(self):
        print(f'Starting DNS brute forcing with {len(self.list)} words')
        checker = hostchecker.Checker(
            self.list) if self.dnsserver == [] or self.dnsserver == "" or self.dnsserver is None \

# Path: theHarvester/lib/hostchecker.py
# class Checker:
#     def __init__(self, hosts: list, nameserver=False):
#     async def query(host, resolver) -> Tuple[str, Any]:
#     async def query_all(self, resolver) -> list:
#     async def check(self):


# Path: theHarvester/discovery/dnssearch.py
import re
import sys
from aiodns import DNSResolver
from ipaddress import IPv4Network
from typing import Callable, List, Optional
from theHarvester.lib import hostchecker

#####################################################################
# DNS FORCE
#####################################################################


class DnsForce:

    def __init__(self, domain, dnsserver, verbose=False):
        self.domain = domain
        self.subdo = False
        self.verbose = verbose
        # self.dnsserver = [dnsserver] if isinstance(dnsserver, str) else dnsserver
        self.dnsserver = list(map(str, dnsserver.split(','))) if isinstance(dnsserver, str) else dnsserver
        try:
            with open('/etc/theHarvester/wordlists/dns-names.txt', 'r') as file:
                self.list = file.readlines()
        except FileNotFoundError:
            try:
                with open('/usr/local/etc/theHarvester/wordlists/dns-names.txt', 'r') as file:
                    self.list = file.readlines()
            except FileNotFoundError:
                with open('wordlists/dns-names.txt', 'r') as file:
                    self.list = file.readlines()
        self.domain = domain.replace('www.', '')
        self.list = [f'{word.strip()}.{self.domain}' for word in self.list]

    async def run(self):
        print(f'Starting DNS brute forcing with {len(self.list)} words')
        checker = hostchecker.Checker(
            self.list) if self.dnsserver == [] or self.dnsserver == "" or self.dnsserver is None \

            else hostchecker.Checker(self.list, nameserver=self.dnsserver)