fully qualified hostname ?
jon at rdt.monash.edu.au
Fri Aug 27 04:00:05 CEST 1999
Ted Horst <Ted.Horst at wdr.com> writes:
>> >What is the best way to get the fully qualified hostname in python (ie
>> >hostname.domainname) ?
>> >A portable solution would be ideal, but I would settle for Unix only.
Under Unix, I get the best (i.e. least surprising) results using the
following gethostname function:
d = socket.gethostbyaddr(name)
names = [ d ] + d + d
names = getdnsnames(name)
for dnsname in names:
if '.' in dnsname:
fullname = dnsname
fullname = name
fullname = socket.gethostname()
if '.' not in fullname:
fullname = resolve(fullname)
jon at dstc.edu.au
More information about the Python-list