diff --git a/modules/ldapstatus/lib/Tester.php b/modules/ldapstatus/lib/Tester.php
index ef8da951bb0666cec2514a609249271215b553b4..85f568f85524886e19c8eebcbaaf5fc07f8b6f62 100644
--- a/modules/ldapstatus/lib/Tester.php
+++ b/modules/ldapstatus/lib/Tester.php
@@ -78,15 +78,24 @@ class sspmod_ldapstatus_Tester {
 	
 	/**
 	 * TCP ping implemented in php.
-	 * Warning: Will return Success if hostname is illegal. should be fixed.
 	 *
-	 * @param $host Hostname
-	 * @param $port Port number (TCP)
+	 * @param string $host Hostname
+	 * @param int $port Port number (TCP)
 	 */
 	public function phpping($host, $port) {
-	
+		assert('is_string($host)');
+		assert('is_int($port)');
+
 		$this->log('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' );
-	
+
+		$ips = gethostbynamel($host);
+		if ($ips === FALSE) {
+			return array(FALSE, 'Unable to look up hostname ' . $host . '.');
+		}
+		if (count($ips) === 0) {
+			return array(FALSE, 'No IP address found for host ' . $host . '.');
+		}
+
 		$timeout = 1.0;
 		$socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
 		if ($socket) @fclose($socket);