SILENT KILLERPanel

Current Path: > > opt > > hc_python > lib > python3.12 > > site-packages > > dns


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt//hc_python/lib/python3.12//site-packages//dns

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
dnssecalgs Directory - -
quic Directory - -
rdtypes Directory - -
__init__.py File 1663 bytes April 04 2025 08:02:26.
_asyncbackend.py File 2396 bytes April 04 2025 08:02:26.
_asyncio_backend.py File 9051 bytes April 04 2025 08:02:26.
_ddr.py File 5247 bytes April 04 2025 08:02:26.
_features.py File 2492 bytes April 04 2025 08:02:26.
_immutable_ctx.py File 2459 bytes April 04 2025 08:02:26.
_trio_backend.py File 8473 bytes April 04 2025 08:02:26.
asyncbackend.py File 2796 bytes April 04 2025 08:02:26.
asyncquery.py File 30821 bytes April 04 2025 08:02:26.
asyncresolver.py File 17852 bytes April 04 2025 08:02:26.
dnssec.py File 41717 bytes April 04 2025 08:02:26.
dnssectypes.py File 1799 bytes April 04 2025 08:02:26.
e164.py File 3978 bytes April 04 2025 08:02:26.
edns.py File 17089 bytes April 04 2025 08:02:26.
entropy.py File 4242 bytes April 04 2025 08:02:26.
enum.py File 3691 bytes April 04 2025 08:02:26.
exception.py File 5953 bytes April 04 2025 08:02:26.
flags.py File 2750 bytes April 04 2025 08:02:26.
grange.py File 2144 bytes April 04 2025 08:02:26.
immutable.py File 2017 bytes April 04 2025 08:02:26.
inet.py File 5772 bytes April 04 2025 08:02:26.
ipv4.py File 2552 bytes April 04 2025 08:02:26.
ipv6.py File 6554 bytes April 04 2025 08:02:26.
message.py File 68185 bytes April 04 2025 08:02:26.
name.py File 42778 bytes April 04 2025 08:02:26.
namedict.py File 4000 bytes April 04 2025 08:02:26.
nameserver.py File 10115 bytes April 04 2025 08:02:26.
node.py File 12663 bytes April 04 2025 08:02:26.
opcode.py File 2730 bytes April 04 2025 08:02:26.
py.typed File 0 bytes April 04 2025 08:02:26.
query.py File 56298 bytes April 04 2025 08:02:26.
rcode.py File 4156 bytes April 04 2025 08:02:26.
rdata.py File 31022 bytes April 04 2025 08:02:26.
rdataclass.py File 2984 bytes April 04 2025 08:02:26.
rdataset.py File 16664 bytes April 04 2025 08:02:26.
rdatatype.py File 7448 bytes April 04 2025 08:02:26.
renderer.py File 11254 bytes April 04 2025 08:02:26.
resolver.py File 73730 bytes April 04 2025 08:02:26.
reversename.py File 3828 bytes April 04 2025 08:02:26.
rrset.py File 9170 bytes April 04 2025 08:02:26.
serial.py File 3606 bytes April 04 2025 08:02:26.
set.py File 9213 bytes April 04 2025 08:02:26.
tokenizer.py File 23583 bytes April 04 2025 08:02:26.
transaction.py File 22589 bytes April 04 2025 08:02:26.
tsig.py File 11413 bytes April 04 2025 08:02:26.
tsigkeyring.py File 2633 bytes April 04 2025 08:02:26.
ttl.py File 2977 bytes April 04 2025 08:02:26.
update.py File 12243 bytes April 04 2025 08:02:26.
version.py File 1926 bytes April 04 2025 08:02:26.
versioned.py File 11765 bytes April 04 2025 08:02:26.
win32util.py File 8874 bytes April 04 2025 08:02:26.
wire.py File 2830 bytes April 04 2025 08:02:26.
xfr.py File 13271 bytes April 04 2025 08:02:26.
zone.py File 52086 bytes April 04 2025 08:02:26.
zonefile.py File 27926 bytes April 04 2025 08:02:26.
zonetypes.py File 690 bytes April 04 2025 08:02:26.

Reading File: //opt//hc_python/lib/python3.12//site-packages//dns/win32util.py

import sys

import dns._features

if sys.platform == "win32":
    from typing import Any

    import dns.name

    _prefer_wmi = True

    import winreg  # pylint: disable=import-error

    # Keep pylint quiet on non-windows.
    try:
        _ = WindowsError  # pylint: disable=used-before-assignment
    except NameError:
        WindowsError = Exception

    if dns._features.have("wmi"):
        import threading

        import pythoncom  # pylint: disable=import-error
        import wmi  # pylint: disable=import-error

        _have_wmi = True
    else:
        _have_wmi = False

    def _config_domain(domain):
        # Sometimes DHCP servers add a '.' prefix to the default domain, and
        # Windows just stores such values in the registry (see #687).
        # Check for this and fix it.
        if domain.startswith("."):
            domain = domain[1:]
        return dns.name.from_text(domain)

    class DnsInfo:
        def __init__(self):
            self.domain = None
            self.nameservers = []
            self.search = []

    if _have_wmi:

        class _WMIGetter(threading.Thread):
            # pylint: disable=possibly-used-before-assignment
            def __init__(self):
                super().__init__()
                self.info = DnsInfo()

            def run(self):
                pythoncom.CoInitialize()
                try:
                    system = wmi.WMI()
                    for interface in system.Win32_NetworkAdapterConfiguration():
                        if interface.IPEnabled and interface.DNSServerSearchOrder:
                            self.info.nameservers = list(interface.DNSServerSearchOrder)
                            if interface.DNSDomain:
                                self.info.domain = _config_domain(interface.DNSDomain)
                            if interface.DNSDomainSuffixSearchOrder:
                                self.info.search = [
                                    _config_domain(x)
                                    for x in interface.DNSDomainSuffixSearchOrder
                                ]
                            break
                finally:
                    pythoncom.CoUninitialize()

            def get(self):
                # We always run in a separate thread to avoid any issues with
                # the COM threading model.
                self.start()
                self.join()
                return self.info

    else:

        class _WMIGetter:  # type: ignore
            pass

    class _RegistryGetter:
        def __init__(self):
            self.info = DnsInfo()

        def _split(self, text):
            # The windows registry has used both " " and "," as a delimiter, and while
            # it is currently using "," in Windows 10 and later, updates can seemingly
            # leave a space in too, e.g. "a, b".  So we just convert all commas to
            # spaces, and use split() in its default configuration, which splits on
            # all whitespace and ignores empty strings.
            return text.replace(",", " ").split()

        def _config_nameservers(self, nameservers):
            for ns in self._split(nameservers):
                if ns not in self.info.nameservers:
                    self.info.nameservers.append(ns)

        def _config_search(self, search):
            for s in self._split(search):
                s = _config_domain(s)
                if s not in self.info.search:
                    self.info.search.append(s)

        def _config_fromkey(self, key, always_try_domain):
            try:
                servers, _ = winreg.QueryValueEx(key, "NameServer")
            except WindowsError:
                servers = None
            if servers:
                self._config_nameservers(servers)
            if servers or always_try_domain:
                try:
                    dom, _ = winreg.QueryValueEx(key, "Domain")
                    if dom:
                        self.info.domain = _config_domain(dom)
                except WindowsError:
                    pass
            else:
                try:
                    servers, _ = winreg.QueryValueEx(key, "DhcpNameServer")
                except WindowsError:
                    servers = None
                if servers:
                    self._config_nameservers(servers)
                    try:
                        dom, _ = winreg.QueryValueEx(key, "DhcpDomain")
                        if dom:
                            self.info.domain = _config_domain(dom)
                    except WindowsError:
                        pass
            try:
                search, _ = winreg.QueryValueEx(key, "SearchList")
            except WindowsError:
                search = None
            if search is None:
                try:
                    search, _ = winreg.QueryValueEx(key, "DhcpSearchList")
                except WindowsError:
                    search = None
            if search:
                self._config_search(search)

        def _is_nic_enabled(self, lm, guid):
            # Look in the Windows Registry to determine whether the network
            # interface corresponding to the given guid is enabled.
            #
            # (Code contributed by Paul Marks, thanks!)
            #
            try:
                # This hard-coded location seems to be consistent, at least
                # from Windows 2000 through Vista.
                connection_key = winreg.OpenKey(
                    lm,
                    r"SYSTEM\CurrentControlSet\Control\Network"
                    r"\{4D36E972-E325-11CE-BFC1-08002BE10318}"
                    rf"\{guid}\Connection",
                )

                try:
                    # The PnpInstanceID points to a key inside Enum
                    (pnp_id, ttype) = winreg.QueryValueEx(
                        connection_key, "PnpInstanceID"
                    )

                    if ttype != winreg.REG_SZ:
                        raise ValueError  # pragma: no cover

                    device_key = winreg.OpenKey(
                        lm, rf"SYSTEM\CurrentControlSet\Enum\{pnp_id}"
                    )

                    try:
                        # Get ConfigFlags for this device
                        (flags, ttype) = winreg.QueryValueEx(device_key, "ConfigFlags")

                        if ttype != winreg.REG_DWORD:
                            raise ValueError  # pragma: no cover

                        # Based on experimentation, bit 0x1 indicates that the
                        # device is disabled.
                        #
                        # XXXRTH I suspect we really want to & with 0x03 so
                        # that CONFIGFLAGS_REMOVED devices are also ignored,
                        # but we're shifting to WMI as ConfigFlags is not
                        # supposed to be used.
                        return not flags & 0x1

                    finally:
                        device_key.Close()
                finally:
                    connection_key.Close()
            except Exception:  # pragma: no cover
                return False

        def get(self):
            """Extract resolver configuration from the Windows registry."""

            lm = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
            try:
                tcp_params = winreg.OpenKey(
                    lm, r"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
                )
                try:
                    self._config_fromkey(tcp_params, True)
                finally:
                    tcp_params.Close()
                interfaces = winreg.OpenKey(
                    lm,
                    r"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces",
                )
                try:
                    i = 0
                    while True:
                        try:
                            guid = winreg.EnumKey(interfaces, i)
                            i += 1
                            key = winreg.OpenKey(interfaces, guid)
                            try:
                                if not self._is_nic_enabled(lm, guid):
                                    continue
                                self._config_fromkey(key, False)
                            finally:
                                key.Close()
                        except OSError:
                            break
                finally:
                    interfaces.Close()
            finally:
                lm.Close()
            return self.info

    _getter_class: Any
    if _have_wmi and _prefer_wmi:
        _getter_class = _WMIGetter
    else:
        _getter_class = _RegistryGetter

    def get_dns_info():
        """Extract resolver configuration."""
        getter = _getter_class()
        return getter.get()

SILENT KILLER Tool