【问题标题】:Get DNS search suffix in Python在 Python 中获取 DNS 搜索后缀
【发布时间】:2014-02-14 14:33:06
【问题描述】:

有谁知道如何获取客户端上的 DNS 搜索后缀列表 - 手动添加的和 DHCP 分配的。我希望有一个跨平台的解决方案,但只有 Windows 的解决方案可以工作。我在 pywin32 或其他模块中找不到任何东西...

【问题讨论】:

  • 请详细说明您的问题和您已经尝试过的任何代码。

标签: python networking dns pywin32


【解决方案1】:

经过一番调查,似乎没有跨平台的方式,因为操作系统以不同的方式存储此信息。在 Windows 上,我最终通过注册表查询信息:

def getLocalDomainSuffix():
    domainSuffixSet = set()
    netKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters')
    for keyName in ("DhcpDomain", "SearchList"):    
        value, type = _winreg.QueryValueEx(netKey, keyName)
        if value:
            for item in value.split(','):
                domainSuffixSet.add(item)
    return domainSuffixSet

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多