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(
    print name

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

Any help appreciated.

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('', 80) # external
# with output for on port 80 = [(2, 2, 17, '', ('', 80)), (2, 1, 6, '', ('', 80))]

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