diff --git a/library/ipadiscovery.py b/library/ipadiscovery.py
index 6adf42b040688277979696ad2dbf1033f2cb2045..a42bc8565230eb1b28e8b8bb69c2dddd85924e74 100644
--- a/library/ipadiscovery.py
+++ b/library/ipadiscovery.py
@@ -226,6 +226,10 @@ def main():
         module.fail_json(
             msg="Invalid hostname, '%s' must not be used." % hostname)
 
+    # Get domain from first server if domain is not set, but there are servers
+    if opt_domain is None and len(opt_servers) > 0:
+        opt_domain = opt_servers[0][opt_servers[0].find(".")+1:]
+
     # Create the discovery instance
     ds = ipadiscovery.IPADiscovery()