在Python中获取DNS搜索后缀 [英] Get DNS search suffix in Python
本文介绍了在Python中获取DNS搜索后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有人知道如何在客户端上获取DNS搜索后缀的列表-手动添加的后缀和DHCP分配的后缀.我希望有一个跨平台的解决方案,但仅Windows解决方案可以使用.我在pywin32或其他模块中找不到任何东西...
Does anyone know how to get a list of DNS search suffixes on a client - both ones that have been manually added and ones assigned by DHCP. I'd prefer to have a cross-platform solution, but a Windows only solution will work. I couldn't find anything in pywin32 or other modules...
推荐答案
经过一番调查,由于操作系统以不同的方式存储此信息,因此似乎没有一种跨平台的方式.在Windows上,我最终通过注册表查询信息:
After a bit of investigation, it doesn't look like there is a cross-platform way since the OS stores this information differently. On Windows, I ended up querying the information via the registry:
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中获取DNS搜索后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文