Get DNS search suffix in Python

时间秒杀一切 提交于 2019-12-11 22:04:26

问题


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...


回答1:


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


来源:https://stackoverflow.com/questions/21318427/get-dns-search-suffix-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!