try to work around the broken gethostbyaddr more thoroughly
[tests.git] / system / PlcapiUrlScanner.py
index e3e8ee8..71d9c73 100755 (executable)
@@ -10,6 +10,9 @@ import xmlrpc.client
 import traceback
 import ssl
 
+from gethostbyaddr import workaround_gethostbyaddr
+
+
 class PlcapiUrlScanner:
 
     # turns out the config has an ip but no name..
@@ -17,15 +20,14 @@ class PlcapiUrlScanner:
         self.auth = auth
         if not hostname and not ip:
             raise Exception("PlcapiUrlScanner needs _some_ input")
-        if hostname:
-            if not ip:
-                try:
-                    ip = socket.gethostbyname(hostname)
-                except:
-                    hostname = "{}.pl.sophia.inria.fr".format(hostname)
-                    ip = socket.gethostbyname(hostname)
-        else:
-            hostname=socket.gethostbyaddr(ip)[0]
+        if not hostname:
+            hostname = workaround_gethostbyaddr(ip)
+        elif hostname and not ip:
+            try:
+                ip = socket.gethostbyname(hostname)
+            except:
+                hostname = "{}.pl.sophia.inria.fr".format(hostname)
+                ip = socket.gethostbyname(hostname)
         self.hostname = hostname
         self.ip = ip
         self.verbose = verbose