当前位置: 首页>>代码示例>>PHP>>正文


PHP Net_DNS_Resolver::query方法代码示例

本文整理汇总了PHP中Net_DNS_Resolver::query方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_DNS_Resolver::query方法的具体用法?PHP Net_DNS_Resolver::query怎么用?PHP Net_DNS_Resolver::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net_DNS_Resolver的用法示例。


在下文中一共展示了Net_DNS_Resolver::query方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lookup_hosts

 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;
 }
开发者ID:johann8384,项目名称:srv3,代码行数:26,代码来源:test_server.php

示例2: getHostForLookup

 /**
  * 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);
 }
开发者ID:webeith,项目名称:dnsbl,代码行数:26,代码来源:Utils.php

示例3: queryMX

 /**
  * 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);
 }
开发者ID:dxxd116,项目名称:php-smtp-email-validation,代码行数:27,代码来源:smtp_validateEmail.class.php

示例4: connect

	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();
	}
开发者ID:nguyennamtien,项目名称:DXMPP,代码行数:30,代码来源:class_Jabber.php

示例5: queryMX

 /**
  * 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;
 }
开发者ID:lavoiesl,项目名称:smtp-email-validator,代码行数:29,代码来源:Validator.php

示例6: getHostForLookup

 /** 
  * 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);
 }
开发者ID:ookwudili,项目名称:chisimba,代码行数:21,代码来源:DNSBL.php

示例7: validate_email

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;
    }
}
开发者ID:Kraiany,项目名称:kraiany_site_docker,代码行数:31,代码来源:tikilib.php

示例8: get_mx

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;
    }
}
开发者ID:hggh,项目名称:cpves,代码行数:24,代码来源:func.inc.php

示例9: getHostForLookup

 /** 
  * 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);
 }
开发者ID:jimjag,项目名称:Serendipity,代码行数:25,代码来源:DNSBL.php

示例10: validateEmail

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";
					}
				}
//.........这里部分代码省略.........
开发者ID:Naddiseo,项目名称:WW2Game,代码行数:101,代码来源:Email.php

示例11: while

 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);
         }
//.........这里部分代码省略.........
开发者ID:stealthinu,项目名称:pukiwiki_spam_filter,代码行数:101,代码来源:spam_filter.php

示例12: validateEmail


//.........这里部分代码省略.........
                }
            }
        }
        # 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);
开发者ID:bogiesoft,项目名称:hotelmis-ota,代码行数:67,代码来源:validate_email.php


注:本文中的Net_DNS_Resolver::query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。