有谁知道如何获取客户端上的 DNS 搜索后缀列表 - 包括手动添加的后缀和 DHCP 分配的后缀。我希望有一个跨平台的解决方案,但仅限 Windows 的解决方案也可以。我在 pywin32 或其他模块中找不到任何内容...
最佳答案
经过一番调查,似乎没有跨平台的方式,因为操作系统以不同的方式存储这些信息。在 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
关于python - 在Python中获取DNS搜索后缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21318427/