Reputation: 170310
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:
dnsdomainname
which returns itUpvotes: 3
Views: 3423
Reputation: 1008
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
Upvotes: 4
Reputation: 6331
Try:
from socket import gethostname
machine_name=gethostname()
print(machine_name)
Upvotes: 1