Exemplo n.º 1
0
 public static function lookup_hosts($service, $location, $domain)
 {
     $servers = array();
     $ttl = false;
     $host = "_{$service}._udp.{$location}.{$domain}";
     echo "Service: {$service}, Location: {$location}, Domain: {$domain}\r\nHost: {$host}\r\n";
     $servers = cache::cache_get($host);
     if ($servers === false) {
         echo "Cache Status: MISS\r\n";
         $resolver = new Net_DNS_Resolver();
         $response = $resolver->query($host, 'SRV');
         if ($response) {
             foreach ($response->answer as $rr) {
                 if ($ttl !== false) {
                     $ttl = $rr->ttl;
                 }
                 //$servers[$rr->preference][$rr->weight][] = $rr->target.":".$rr->port;
                 $servers[$rr->preference][$rr->weight][] = $rr->target;
             }
         }
         cache::cache_put($host, $servers, $ttl);
     } else {
         echo "Cache Status: HIT\r\n";
     }
     return $servers;
 }
Exemplo n.º 2
0
 /**
  * Get host to lookup. Lookup a host if neccessary and get the
  * complete FQDN to lookup.
  *
  * @param string $host      Host OR IP to use for building the lookup.
  * @param string $blacklist Blacklist to use for building the lookup.
  * @param string $isIP      is IP adress?
  *
  * @return string Ready to use host to lookup
  */
 public static function getHostForLookup($hostname, $blacklist, $isIP = true)
 {
     if ($isIP && filter_var($hostname, FILTER_VALIDATE_IP)) {
         return self::buildLookUpIP($hostname, $blacklist);
     }
     if ($isIP && !filter_var($hostname, FILTER_VALIDATE_IP)) {
         $resolver = new \Net_DNS_Resolver();
         $response = @$resolver->query($hostname);
         $ip = isset($response->answer[0]->address) ? $response->answer[0]->address : null;
         if (!$ip || !filter_var($ip, FILTER_VALIDATE_IP)) {
             return null;
         }
         return self::buildLookUpIP($ip, $blacklist);
     }
     return self::buildLookUpHost($hostname, $blacklist);
 }
 /**
  * Query DNS server for MX entriesg
  * @return 
  */
 function queryMX($domain)
 {
     $hosts = array();
     $mxweights = array();
     if (function_exists('getmxrr')) {
         getmxrr($domain, $hosts, $mxweights);
     } else {
         // windows, we need Net_DNS
         require_once 'Net/DNS.php';
         $resolver = new Net_DNS_Resolver();
         $resolver->debug = $this->debug;
         // nameservers to query
         $resolver->nameservers = $this->nameservers;
         $resp = $resolver->query($domain, 'MX');
         if ($resp) {
             foreach ($resp->answer as $answer) {
                 $hosts[] = $answer->exchange;
                 $mxweights[] = $answer->preference;
             }
         }
     }
     return array($hosts, $mxweights);
 }
Exemplo n.º 4
0
	function connect($server_host,$server_port=5222,$connect_timeout=null,$alternate_ip=false) {

		if (is_null($connect_timeout)) $connect_timeout = DEFAULT_CONNECT_TIMEOUT;
		$connector = $this->_connector;

 		if (!$alternate_ip && class_exists('Net_DNS_Resolver')) {
			// Perform SRV record lookups
			$ndr = new Net_DNS_Resolver();
			$answer = $ndr->query("_xmpp-client._tcp.".$server_host,"SRV");
			if ($answer && count($answer->answer) > 0 && !empty($answer->answer[0]->target)) {
				$alternate_ip = $answer->answer[0]->target;
			}
			unset($answer);
			unset($ndr);
 		}

		$this->_connection = &new $connector();
		$this->_server_host = $server_host;
		$this->_server_port = $server_port;
		$this->_server_ip = $alternate_ip ? $alternate_ip : $server_host;
		$this->_connect_timeout = $connect_timeout;

		$this->roster = array();
		$this->services = array();

		$this->_is_win32 = (substr(strtolower(php_uname()),0,3)=="win");
		$this->_sleep_func = $this->_is_win32 ? "win32_sleep" : "posix_sleep";

		return $this->_connect_socket();
	}
Exemplo n.º 5
0
 /**
  * Query DNS server for MX entries
  * @return
  */
 public function queryMX($domain)
 {
     $hosts = array();
     $mxweights = array();
     if (function_exists('getmxrr')) {
         getmxrr($domain, $hosts, $mxweights);
     } else {
         // windows, we need Net_DNS: http://pear.php.net/package/Net_DNS
         require_once 'Net/DNS.php';
         $resolver = new Net_DNS_Resolver();
         $resolver->debug = $this->debug;
         // nameservers to query
         $resolver->nameservers = $this->nameservers;
         $resp = $resolver->query($domain, 'MX');
         if ($resp) {
             foreach ($resp->answer as $answer) {
                 $hosts[] = $answer->exchange;
                 $mxweights[] = $answer->preference;
             }
         }
     }
     $mxs = array_combine($hosts, $mxweights);
     asort($mxs, SORT_NUMERIC);
     return $mxs;
 }
Exemplo n.º 6
0
 /** 
  * Get host to lookup. Lookup a host if neccessary and get the
  * complete FQDN to lookup.
  *
  * @param  string Host OR IP to use for building the lookup.
  * @param  string Blacklist to use for building the lookup.
  * @access protected
  * @return string Ready to use host to lookup
  */
 function getHostForLookup($host, $blacklist)
 {
     // Currently only works for v4 addresses.
     if (!Net_CheckIP::check_ip($host)) {
         $resolver = new Net_DNS_Resolver();
         $response = $resolver->query($host);
         $ip = $response->answer[0]->address;
     } else {
         $ip = $host;
     }
     return $this->buildLookUpHost($ip, $blacklist);
 }
Exemplo n.º 7
0
function validate_email($email, $checkserver = 'n')
{
    $valid_syntax = eregi("^[_a-z0-9\\+\\.\\-]+@[_a-z0-9\\.\\-]+\\.[a-z]{2,4}\$", $email);
    if (!$valid_syntax) {
        return false;
    } elseif ($checkserver == 'y') {
        include_once 'Net/DNS.php';
        $resolver = new Net_DNS_Resolver();
        $domain = substr(strstr($email, '@'), 1);
        $answer = $resolver->query($domain, 'MX');
        if (!$answer) {
            return false;
        } else {
            foreach ($answer->answer as $server) {
                $mxserver[$server->preference] = $server->exchange;
            }
            krsort($mxserver);
            foreach ($mxserver as $server) {
                $test = fsockopen($server, 25, $errno, $errstr, 15);
                if ($test) {
                    fclose($test);
                    return true;
                }
                fclose($test);
            }
            return false;
        }
    } else {
        return true;
    }
}
Exemplo n.º 8
0
function get_mx($dnsname)
{
    $resolver = new Net_DNS_Resolver();
    $response = $resolver->query($dnsname, 'MX');
    global $res_array;
    if ($response) {
        foreach ($response->answer as $rr) {
            $ipaddr = "";
            $ip_type = "";
            $ipaddr = get_ip_for_a($rr->exchange);
            if (Net_CheckIP::check_ip($ipaddr)) {
                $ip_type = "ipv4";
            }
            if (Net_IPv6::checkIPv6($ipaddr)) {
                $ip_type = "ipv6";
            }
            array_push($res_array, array('prio' => $rr->preference, 'dnsname' => $rr->exchange, 'ipaddr' => $ipaddr, 'iptype' => $ip_type));
        }
        asort($res_array);
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 9
0
 /** 
  * Get host to lookup. Lookup a host if neccessary and get the
  * complete FQDN to lookup.
  *
  * @param string $host      Host OR IP to use for building the lookup.
  * @param string $blacklist Blacklist to use for building the lookup.
  *
  * @access protected
  * @return string Ready to use host to lookup
  */
 protected function getHostForLookup($host, $blacklist)
 {
     // Currently only works for v4 addresses.
     if (filter_var($host, FILTER_VALIDATE_IP)) {
         $ip = $host;
     } else {
         $resolver = new Net_DNS_Resolver();
         $response = $resolver->query($host);
         $ip = isset($response->answer[0]->address) ? $response->answer[0]->address : null;
     }
     if (!$ip || !filter_var($ip, FILTER_VALIDATE_IP)) {
         return;
     }
     return $this->buildLookUpHost($ip, $blacklist);
 }
Exemplo n.º 10
0
function validateEmail($email, $domainCheck = false, $verify = false, $probe_address='', $helo_address='', $return_errors=false) {
	global $debug;
	$server_timeout = 180; # timeout in seconds. Some servers deliberately wait a while (tarpitting)
	if($debug) {echo "<pre>";}
	# Check email syntax with regex
	if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $email, $matches)) {
		$user = $matches[1];
		$domain = $matches[2];
		# Check availability of  MX/A records
		if ($domainCheck) {
			if(function_exists('checkdnsrr')) {
				# Construct array of available mailservers
				if(getmxrr($domain, $mxhosts, $mxweight)) {
					for($i=0;$i<count($mxhosts);$i++){
						$mxs[$mxhosts[$i]] = $mxweight[$i];
					}
					asort($mxs);
					$mailers = array_keys($mxs);
				} elseif(checkdnsrr($domain, 'A')) {
					$mailers[0] = gethostbyname($domain);
				} else {
					$mailers=array();
				}
			} else {
			# DNS functions do not exist - we are probably on Win32.
			# This means we have to resort to other means, like the Net_DNS PEAR class.
			# For more info see http://pear.php.net
			# For this you also need to enable the mhash module (lib_mhash.dll).
			# Another way of doing this is by using a wrapper for Win32 dns functions like
			# the one descrieb at http://px.sklar.com/code.html/id=1304
				require_once 'Net/DNS.php';
				$resolver = new Net_DNS_Resolver();
				# Workaround for bug in Net_DNS, you have to explicitly tell the name servers
				#
				# ***********  CHANGE THIS TO YOUR OWN NAME SERVERS **************
				$resolver->nameservers = array ('217.149.196.6', '217.149.192.6');
				
				$mx_response = $resolver->query($domain, 'MX');
				$a_response  = $resolver->query($domain, 'A');
				if ($mx_response) {
					foreach ($mx_response->answer as $rr) {
							$mxs[$rr->exchange] = $rr->preference;
					}
					asort($mxs);
					$mailers = array_keys($mxs);
				} elseif($a_response) {
					$mailers[0] = gethostbyname($domain);
				} else {
					$mailers = array();
				}
				
			}
			
			$total = count($mailers);
			# Query each mailserver
			if($total > 0 && $verify) {
				# Check if mailers accept mail
				for($n=0; $n < $total; $n++) {
					# Check if socket can be opened
					if($debug) { echo "Checking server $mailers[$n]...\n";}
					$connect_timeout = $server_timeout;
					$errno = 0;
					$errstr = 0;
					# Try to open up socket
					if($sock = @fsockopen($mailers[$n], 25, $errno , $errstr, $connect_timeout)) {
						$response = fgets($sock);
						if($debug) {echo "Opening up socket to $mailers[$n]... Succes!\n";}
						stream_set_timeout($sock, 30);
						$meta = stream_get_meta_data($sock);
						if($debug) { echo "$mailers[$n] replied: $response\n";}
						$cmds = array(
							"HELO $helo_address",
							"MAIL FROM: <$probe_address>",
							"RCPT TO: <$email>",
							"QUIT",
						);
						# Hard error on connect -> break out
						# Error means 'any reply that does not start with 2xx '
						if(!$meta['timed_out'] && !preg_match('/^2\d\d[ -]/', $response)) {
							$error = "Error: $mailers[$n] said: $response\n";
							break;
						}
						foreach($cmds as $cmd) {
							$before = microtime(true);
							fputs($sock, "$cmd\r\n");
							$response = fgets($sock, 4096);
							$t = 1000*(microtime(true)-$before);
							if($debug) {echo htmlentities("$cmd\n$response") . "(" . sprintf('%.2f', $t) . " ms)\n";}
							if(!$meta['timed_out'] && preg_match('/^5\d\d[ -]/', $response)) {
								$error = "Unverified address: $mailers[$n] said: $response";
								break 2;
							}
						}
						fclose($sock);
						if($debug) { echo "Succesful communication with $mailers[$n], no hard errors, assuming OK";}
						break;
					} elseif($n == $total-1) {
						$error = "None of the mailservers listed for $domain could be contacted";
					}
				}
			} elseif($total <= 0) {
				$error = "No usable DNS records found for domain '$domain'";
			}
		}
	} else {
		$error = 'Address syntax not correct';
	}
	if($debug) { echo "</pre>";}
	
	if($return_errors) {
		# Give back details about the error(s).
		# Return FALSE if there are no errors.
		if(isset($error)) return htmlentities($error); else return false;
	} else {
		# 'Old' behaviour, simple to understand
		if(isset($error)) return false; else return true;
	}
}
Exemplo n.º 11
0
 function dns_get_ns($hostname, &$ns_array)
 {
     // 答えを返すところをクリアしておく
     if (!empty($ns_array)) {
         while (array_pop($ns_array)) {
         }
     }
     // まだキャッシュがなければ以前に得た結果のキャッシュファイルを読み込む
     if (empty($this->dns_get_ns_cache)) {
         $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "a+") or die_message('Cannot read dns_get_ns cache file: ' . SPAM_FILTER_DNSGETNS_CACHE_FILE . "\n");
         flock($fp, LOCK_SH);
         while ($csv = fgetcsv($fp, 1000, ",")) {
             $host = array_shift($csv);
             $time = $csv[0];
             if ($time + SPAM_FILTER_DNSGETNS_CACHE_DAY * 24 * 60 * 60 < time()) {
                 continue;
             }
             // 古すぎる情報は捨てる
             $this->dns_get_ns_cache["{$host}"] = $csv;
         }
         flock($fp, LOCK_UN);
         fclose($fp);
     }
     // キャッシュの結果に入ってるならそこから結果を引いて返す
     $cache = $this->dns_get_ns_cache["{$hostname}"];
     if (!empty($cache)) {
         $time = array_shift($cache);
         foreach ($cache as $ns) {
             $ns_array[] = $ns;
         }
         return TRUE;
     }
     // ホスト名を上から一つづつ減らしてNSが得られるまで試す
     // 例: www.subdomain.example.com→subdomain.example.com→example.com
     $domain_array = explode(".", $hostname);
     $ns_found = FALSE;
     do {
         $domain = implode(".", $domain_array);
         // 環境で使える手段に合わせてドメインのNSを得る
         if (function_exists('dns_get_record')) {
             // 内部関数 dns_get_record 使える場合
             $lookup = dns_get_record($domain, DNS_NS);
             if (!empty($lookup)) {
                 foreach ($lookup as $record) {
                     $ns_array[] = $record['target'];
                 }
                 $ns_found = TRUE;
             }
         } else {
             if (include_once 'Net/DNS.php') {
                 // PEARのDNSクラスが使える場合
                 $resolver = new Net_DNS_Resolver();
                 if (SPAM_FILTER_IS_WINDOWS) {
                     $resolver->nameservers[0] = $this->getDNSServer();
                 }
                 $response = $resolver->query($domain, 'NS');
                 if ($response) {
                     foreach ($response->answer as $rr) {
                         if ($rr->type == "NS") {
                             $ns_array[] = $rr->nsdname;
                         } else {
                             if ($rr->type == "CNAME") {
                                 // CNAMEされてるときは、そっちを再帰で引く
                                 $this->dns_get_ns($rr->rdatastr(), $ns_array);
                             }
                         }
                     }
                     $ns_found = TRUE;
                 }
             } else {
                 // PEARも使えない場合、外部コマンドnslookupによりNSを取得
                 is_executable(SPAM_FILTER_NSLOOKUP_PATH) or die_message("Cannot execute nslookup. see NSLOOKUP_PATH setting.\n");
                 @exec(SPAM_FILTER_NSLOOKUP_PATH . " -type=ns " . $domain, $lookup);
                 foreach ($lookup as $line) {
                     if (preg_match('/\\s*nameserver\\s*=\\s*(\\S+)$/', $line, $ns) || preg_match('/\\s*origin\\s*=\\s*(\\S+)$/', $line, $ns) || preg_match('/\\s*primary name server\\s*=\\s*(\\S+)$/', $line, $ns)) {
                         $ns_array[] = $ns[1];
                         $ns_found = TRUE;
                     }
                 }
             }
         }
     } while (!$ns_found && array_shift($domain_array) != NULL);
     // NSが引けていたら、結果をキャッシュに入れて保存
     if ($ns_found) {
         // 結果をキャッシュに登録
         $cache = $ns_array;
         array_unshift($cache, time());
         // 引いた時間も保持
         $this->dns_get_ns_cache["{$hostname}"] = $cache;
         // キャッシュをファイルに保存
         $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "w") or die_message("Cannot write dns_get_ns cache file: " . SPAM_FILTER_DNSGETNS_CACHE_FILE . "\n");
         flock($fp, LOCK_EX);
         foreach ($this->dns_get_ns_cache as $host => $cachedata) {
             $csv = $host;
             foreach ($cachedata as $data) {
                 $csv .= "," . $data;
             }
             $csv .= "\n";
             fputs($fp, $csv);
         }
         flock($fp, LOCK_UN);
         fclose($fp);
     }
     return $ns_found;
 }
Exemplo n.º 12
0
function validateEmail($email, $domainCheck = false, $verify = false, $probe_address = '', $helo_address = '', $return_errors = false)
{
    global $debug;
    $debug = false;
    /*
        Time-outs.
        Be sure to have set PHP's "max_execution_time" to some value greater than the total time of the
        communication. This means of course also (a fair amount) larger than any of the next two values.
        Of course, large timeouts will cause the verification to take alot of time. There are servers
        that have configured such large delays that they are unsuitable for verifcation with a web page.
    
        TCP connect timeout (seconds). Some servers deliberately wait a while before responding (tarpitting). */
    $tcp_connect_timeout = 18000;
    /*
    Some server (exim) can be configured to wait before acknowledging. If you issues the next command
    too soon, it will drop the SMTP conversation with stuff like: "554 SMTP synchronization error".
    */
    $smtp_timeout = 6000;
    if ($debug) {
        echo "<pre>";
    }
    # Check email syntax with regex
    if (preg_match('/^([a-zA-Z0-9\'\\._\\+-]+)\\@((\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,7}|[0-9]{1,3})(\\]?))$/', $email, $matches)) {
        $user = $matches[1];
        $domain = $matches[2];
        // if only a@b.com or test@xyz.com then fail
        if (strlen($user) <= 1 || strpos($user, 'test') !== false) {
            return false;
        }
        return true;
        /*
            Some MTAs do not like people ringing their door bell too much.
            If this is the case, sender    verification will get your IP address
            blacklisted. This is a problem when your web server is also a
            mail server. If you MTA is Postfix, you can whitelist addresses
            so that they are not verified any more:
            in Postfix, see    http://www.postfix.org/ADDRESS_VERIFICATION_README.html#sender_always
            This list should be taken into account by this script, otherwise 
            your IP address will get blacklisted anyway.
            The code below ONLY works when the access list is of type 'pcre', see
            http://www.postfix.org/pcre_table.5.html for how to construct this.
        */
        $whitelist = dirname(__FILE__) . '/whitelist.txt';
        if ($exluded = explode("\n", @file_get_contents($whitelist))) {
            if ($debug) {
                echo "in file {$whitelist}\n";
            }
            $regexes = array();
            foreach ($exluded as $line) {
                if ($debug) {
                    echo "whitelist line {$line}\n";
                }
                preg_match('/^(\\/.*?\\/)\\s+OK/', $line, $matches);
                if (@$matches[1]) {
                    if ($debug) {
                        echo "found whitelist {$matches['1']}\n";
                    }
                    array_push($regexes, $matches[1]);
                }
            }
            foreach ($regexes as $regex) {
                if ($debug) {
                    echo "compare domain {$regex} in {$email}\n";
                }
                preg_match($regex, "{$user}@{$domain}", $m);
                if (@$m[0]) {
                    if ($debug) {
                        echo "{$whitelist} contains matching whitelist regex '" . $regex . "'\n";
                    }
                    if ($return_errors) {
                        # Give back details about the error(s).
                        # Return FALSE if there are no errors.
                        if (isset($error)) {
                            return htmlentities($error);
                        } else {
                            return false;
                        }
                    } else {
                        # 'Old' behaviour, simple to understand
                        if (isset($error)) {
                            return false;
                        } else {
                            return true;
                        }
                    }
                }
            }
        }
        # Check availability of  MX/A records
        if ($domainCheck) {
            if (function_exists('checkdnsrr')) {
                # Construct array of available mailservers
                getmxrr($domain, $mxhosts, $mxweight);
                if (count($mxhosts) > 0) {
                    for ($i = 0; $i < count($mxhosts); $i++) {
                        $mxs[$mxhosts[$i]] = $mxweight[$i];
                    }
                    asort($mxs);
                    $mailers = array_keys($mxs);
                    # No MX found, use A
                } elseif (checkdnsrr($domain, 'A')) {
                    $mailers[0] = gethostbyname($domain);
                } else {
                    $mailers = array();
                }
            } else {
                # DNS functions do not exist - we are probably on Win32.
                # This means we have to resort to other means, like the Net_DNS PEAR class.
                # For more info see http://pear.php.net
                # For this you also need to enable the mhash module (lib_mhash.dll).
                # Another way of doing this is by using a wrapper for Win32 dns functions like
                # the one descrieb at http://px.sklar.com/code.html/id=1304
                require_once 'Net/DNS.php';
                $resolver = new Net_DNS_Resolver();
                # Workaround for bug in Net_DNS, you have to explicitly tell the name servers
                #
                # ***********  CHANGE THIS TO YOUR OWN NAME SERVERS **************
                $resolver->nameservers = array('217.149.196.6', '217.149.192.6');
                $mx_response = $resolver->query($domain, 'MX');
                $a_response = $resolver->query($domain, 'A');
                if ($mx_response) {
                    foreach ($mx_response->answer as $rr) {
                        $mxs[$rr->exchange] = $rr->preference;
                    }
                    asort($mxs);
                    $mailers = array_keys($mxs);
                } elseif ($a_response) {
                    $mailers[0] = gethostbyname($domain);
                } else {
                    $mailers = array();
                }
            }
            $total = count($mailers);
            # Query each mailserver
            if ($total > 0 && $verify) {
                # Check if mailers accept mail
                for ($n = 0; $n < $total; $n++) {
                    # Check if socket can be opened
                    if ($debug) {
                        echo "Checking server {$mailers[$n]}...\n";
                    }
                    $errno = 0;
                    $errstr = 0;
                    # Try to open up TCP socket
                    if ($sock = @fsockopen($mailers[$n], 25, $errno, $errstr, $tcp_connect_timeout)) {
                        $response = fread($sock, 8192);
                        if ($debug) {
                            echo "Opening up socket to {$mailers[$n]}... Success!\n";
                        }
                        stream_set_timeout($sock, $smtp_timeout);
                        $meta = stream_get_meta_data($sock);
                        if ($debug) {
                            echo "{$mailers[$n]} replied: {$response}\n";
                        }
                        $cmds = array("HELO {$helo_address}", "MAIL FROM: <{$probe_address}>", "RCPT TO:<{$email}>", "QUIT");
                        # Hard error on connect -> break out
                        # Error means 'any reply that does not start with 2xx '
                        if (!$meta['timed_out'] && !preg_match('/^2\\d\\d[ -]/', $response)) {
                            $error = "Error: {$mailers[$n]} said: {$response}\n";
                            break;
                        }
                        foreach ($cmds as $cmd) {
                            $before = microtime(true);
                            fputs($sock, "{$cmd}\r\n");
                            $response = fread($sock, 4096);
                            $t = 1000 * (microtime(true) - $before);
                            if ($debug) {
                                echo htmlentities("{$cmd}\n{$response}") . "(" . sprintf('%.2f', $t) . " ms)\n";
                            }
                            if (!$meta['timed_out'] && preg_match('/^5\\d\\d[ -]/', $response)) {
                                $error = "Unverified address: {$mailers[$n]} said: {$response}";
                                break 2;
                            }
                        }
                        fclose($sock);
                        if ($debug) {
                            echo "Succesful communication with {$mailers[$n]}, no hard errors, assuming OK";
                        }
                        break;
                    } elseif ($n == $total - 1) {
                        $error = "None of the mailservers listed for {$domain} could be contacted";
                    }
                }
            } elseif ($total <= 0) {
                $error = "No usable DNS records found for domain '{$domain}'";
            }
        }
    } else {
        $error = 'Address syntax not correct';
    }
    if ($debug) {
        echo "</pre>";
    }
    if ($return_errors) {
        # Give back details about the error(s).
        # Return FALSE if there are no errors.
        if (isset($error)) {
            return nl2br(htmlentities($error));
        } else {
            return false;
        }
    } else {
        # 'Old' behaviour, simple to understand
        if (isset($error)) {
            return false;
        } else {
            return true;
        }
    }
}