Get DNS Style Domain Name

Posted by grimhacker on 2013-02-04 08:27

What's the function to get the dns style domain names that are present on the local network?

I know you can get the netbios style domain names using:

import win32com.client
network = win32com.client.GetObject ("WinNT:")
for group in network:
    name = str(group.name)
    print name

Which outputs something like:
COMPANY_NAME
WORKGROUP
I need the dns style (e.g. COMPANY_NAME.local)

Any help appreciated.
Thanks.

sophisticated | Thu, 2014-10-02 04:08

Can you just use socket which should work on both, external and internal:

import socket
print socket.getaddrinfo('www.elvidence.com.au', 80) # external
# with output for http://www.elvidence.com.au on port 80 = [(2, 2, 17, '', ('181.224.149.10', 80)), (2, 1, 6, '', ('181.224.149.10', 80))]

print socket.gethostbyname('localhost') # and this example for localhost or any internal host name inside your domain