How to get login computer's domain name?

Donn Cave donn at u.washington.edu
Fri May 24 14:13:40 EDT 2002


Quoth "James J. Besemer" <jb at cascade-sys.com>:
|
|     import socket
|     socket.gethostname()

Nah, that's the host name, not the domain name.  It may yield a
domain name at some sites, but that seems to be relatively rare.

   name, hlist, alist = socket.gethostbyaddr(socket.gethostbyname(socket.gethostname()))

will work in many cases - where the host name is configured correctly,
/etc/hosts doesn't list the short version first, and of course where
there is a single unambiguous answer to the question.

	Donn Cave, donn at u.washington.edu

| "Beverly K. Pope" wrote:
|
| > Is there a module that has commands for getting the domain name of the
| > computer to which I am logged in (not "local")?  Or do I have to open
| > a pipe to the appropriate command?



More information about the Python-list mailing list