On 11/19/2013 02:25 PM, John Ferlan wrote:
Using just socket.gethostbyaddr(socket.gethostname())[0] caused some
issues recently in one of my DHCP testing environments. Breaking down
the calls showed the following:
>>> socket.gethostname()
'dhcp-186-211.bos.redhat.com'
>>> socket.gethostbyname("dhcp-186-211.bos.redhat.com")
'10.16.186.211'
>>> socket.gethostbyaddr(socket.gethostname())[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.herror: [Errno 1] Unknown host
While just a socket.gethostname() could have worked, using the
socket.getfqdn() seemed to be safer just in case.
---
lib/VirtLib/live.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py
index c929e71..6a10474 100644
--- a/lib/VirtLib/live.py
+++ b/lib/VirtLib/live.py
@@ -100,6 +100,9 @@ def hostname(server):
return out
def full_hostname(server):
- """To return the fully qualifiec domain name(FQDN) of the
system"""
+ """To return the fully qualified domain name(FQDN) of the
system"""
- return socket.gethostbyaddr(socket.gethostname())[0]
+ if socket.getfqdn().find('.') >= 0:
+ return socket.getfqdn()
+ else:
+ return socket.gethostbyaddr(socket.gethostname())[0]
The server parameter seems to be entirely superfluous,
which makes me believe that the original intention might have
been something like (roughly)
return socket.gethostbyaddr(server)
which by itself will probably not solve the reverse lookup
issue you seem to have experienced
--
Mit freundlichen Grüßen/Kind Regards
Viktor Mihajlovski
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martina Köderitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294