Skip to content

Instantly share code, notes, and snippets.

Created August 27, 2013 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Caustic/6358824 to your computer and use it in GitHub Desktop.
Save Caustic/6358824 to your computer and use it in GitHub Desktop.
vagrant bugreport
def getfqdn(name=''):
"""Get fully qualified domain name from name.
An empty argument is interpreted as meaning the local host.
First the hostname returned by gethostbyaddr() is checked, then
possibly existing aliases. In case no FQDN is available, hostname
from gethostname() is returned.
name = name.strip()
if not name or name == '':
name = gethostname()
hostname, aliases, ipaddrs = gethostbyaddr(name)
except error:
aliases.insert(0, hostname)
for name in aliases:
if '.' in name:
name = hostname
return name
ubuntu@graph:~$ cat /etc/hosts localhost graph graph precise
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Last login: Tue Aug 27 13:22:48 2013 from
ubuntu@graph:~$ python
Python 2.7.3 (default, Apr 10 2013, 06:20:15)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostname()
>>> socket.getfqdn()
>>> socket.gethostbyaddr('graph')
('graph', ['graph', '', 'precise'], [''])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment