3

I am looking for a Python solution for obtaining the current machine default domain name, one that will work on Linux, Mac OS X and Windows.

So far I discovered that:

  • Linux has dnsdomainname which returns it
2
  • 1
    Have you tried the solution here? Commented Jan 19, 2016 at 14:17
  • 1
    Also try here Commented Jan 19, 2016 at 14:21

2 Answers 2

4

Try:

#!/usr/bin/env python

import socket

def get_dns_domain():
    return socket.getfqdn().split('.', 1)[1]

print (get_dns_domain()) # to match python>2.7
Sign up to request clarification or add additional context in comments.

Comments

1

Try:

from socket import gethostname
machine_name=gethostname()
print(machine_name)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.