本文整理汇总了PHP中Net_DNS_Resolver类的典型用法代码示例。如果您正苦于以下问题:PHP Net_DNS_Resolver类的具体用法?PHP Net_DNS_Resolver怎么用?PHP Net_DNS_Resolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Net_DNS_Resolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例3: olc_get_ip_info
function olc_get_ip_info(&$smarty)
{
if (SHOW_IP_LOG == TRUE_STRING_S) {
$customers_ip_text = 'CUSTOMERS_IP';
$ip = $_SESSION[$customers_ip_text];
if (!isset($ip)) {
$ip = $_SERVER['REMOTE_ADDR'];
if (strlen($ip) > 0) {
if (function_exists("gethostbyaddr")) {
//Get host-name for IP by built-in PHP-function
$host = gethostbyaddr($ip);
}
if (strlen($host) == 0) {
//"gethostbyaddr" does not work always, so try "Net_DNS" first
define('FILENAME_NET_DNS', '"Net/DNS.php');
if (file_exists(FILENAME_NET_DNS)) {
require_once FILENAME_NET_DNS;
$res = new Net_DNS_Resolver();
$ans = $res->search($ip, "MX");
if ($ans) {
$host = $ans->answer[0]->ptrdname;
}
}
}
if (strlen($host) > 0) {
if ($host != $ip) {
$ip .= LPAREN . $host . RPAREN;
}
}
$ip .= ' -- Datum: ' . date("d.m.Y H:i:s");
$_SESSION[$customers_ip_text] = $ip;
}
}
if ($smarty) {
$smarty->assign('IP_LOG', true);
$smarty->assign($customers_ip_text, $ip);
}
}
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
}
示例8: 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);
}
示例9: Resolve
/**
* @brief Resolve a LSID using the DNS
*
*
*/
function Resolve($lsid_to_resolve)
{
$result = true;
$this->lsid = new LSID($lsid_to_resolve);
$ndr = new Net_DNS_Resolver();
$answer = $ndr->search("_lsid._tcp." . $this->lsid->getAuthority(), "SRV");
if ($answer == false) {
$result = false;
} else {
if ($this->debug) {
echo "<pre>";
print_r($answer->answer);
echo "</pre>";
}
}
$this->server = $answer->answer[0]->target;
$this->port = $answer->answer[0]->port;
if ($this->report) {
echo "<p>";
echo "Authority for <strong>{$lsid_to_resolve}</strong> ";
if ($result) {
echo "is located at: ", $this->server, ":", $this->port;
} else {
echo "not found";
}
echo "</p>";
}
return $result;
}
示例10: 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);
}
示例11: 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";
}
}
//.........这里部分代码省略.........
示例12: dns_get_ns
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);
}
//.........这里部分代码省略.........
示例13: validateEmail
//.........这里部分代码省略.........
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);
示例14: getdnsattributes_VMWO
function getdnsattributes_VMWO($l, $ip)
{
$r = new Net_DNS_Resolver();
$r->nameservers = array("ws1.maxmind.com");
$p = $r->search($l . "." . $ip . ".s.maxmind.com", "TXT", "IN");
$str = is_object($p->answer[0]) ? $p->answer[0]->string() : '';
//ereg("\"(.*)\"",$str,$regs); // mike challis PHP5.3 fix
preg_match("/\"(.*)\"/", $str, $regs);
$str = isset($regs[1]) ? $regs[1] : '';
return $str;
}
示例15: ZoneAXFR
function ZoneAXFR($domain, $server)
{
require_once "Net/DNS.php";
$res = new Net_DNS_Resolver();
//$res->debug = 1;
$res->persistent_tcp = 1;
$res->nameservers = array($server);
$answer = $res->axfr($domain);
/*
echo "<pre>";
var_dump($answer);
//var_dump($res);
//var_dump($answer[0]->header->rcode);
echo "</pre>";
exit;
*/
// check for errors
/*
if ($res->errorstring != "NOERROR") {
$this->err=70;
$this->errstr .= sprintf(my_("Zone transfer for domain %s failed with message %s"), $this->domain, $res->errorstring)."\n";
return "";
}
*/
if ($answer) {
$this->hname = array();
$i = 1;
// kill form information
foreach ($answer as $rr) {
if ($rr->type == "SOA") {
//var_dump($rr);
$this->ttl = $rr->ttl;
$this->refresh = $rr->refresh;
$this->retry = $rr->retry;
$this->expire = $rr->expire;
$this->minimum = $rr->minimum;
$this->responsiblemail = $rr->rname;
}
if ($rr->type == "NS" and $rr->name == $this->domain) {
$this->hname[$i++] = $this->strip_domain($rr->nsdname, $this->domain);
}
}
$this->err = 0;
return $answer;
} else {
$this->errstr .= sprintf(my_("Zone transfer for domain %s failed - using defaults: %s"), $this->domain, $res->errorstring) . "\n";
// could not do transfer, so use defaults from now on!
$this->err = -1;
return "";
}
}