本文整理汇总了PHP中dns_get_record函数的典型用法代码示例。如果您正苦于以下问题:PHP dns_get_record函数的具体用法?PHP dns_get_record怎么用?PHP dns_get_record使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dns_get_record函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserIpAddress
public function getUserIpAddress()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$is_local_network = false;
if (strpos($ip, '192.168') === 0 || strpos($ip, '10.') === 0 || strpos($ip, '172.16') === 0 || strpos($ip, '172.31') === 0 || strpos($ip, '172.0.0.1') === 0) {
$is_local_network = true;
}
if ($is_local_network) {
$ips = dns_get_record($_SERVER['SERVER_NAME']);
foreach ($ips as $item) {
if (isset($item['type'])) {
if ($item['type'] == 'A') {
if (isset($item['ip'])) {
//die('ext '.$item['ip']);
return $item['ip'];
break;
}
}
}
}
} else {
//die('ip '.$ip);
return $ip;
}
}
示例2: getRecordsRecursivly
/**
* Tries to load the DNS records for the passed domain and type recursively
* by using the PHP dns_get_record() function.
*
* @param string $domain The domain to load the DNS record for
* @param string $type The type to load the DNS recored for
*
* @return array The DNS recored
* @throws \Exception Is thrown if the passed is not supported
*/
protected function getRecordsRecursivly($domain, $type)
{
// prepare the result nd the constant name
$result = array();
$dnsConstName = $this->getDnsConstName($type);
// query whether or not the type is supported
if (!$dnsConstName) {
throw new \Exception('Not supported dns type to query.');
}
// load the answer name and the available DNS records
$dnsAnswerName = $this->dnsAnswerNames[$dnsConstName];
$records = dns_get_record($domain, constant($dnsConstName));
// declare the array for the answers
$answer = array();
// prepare the answer
foreach ($records as $record) {
if (is_array($dnsAnswerName)) {
foreach ($dnsAnswerName as $name) {
$answer[$name] = $record[$name];
}
} else {
$answer = $record[$dnsAnswerName];
}
// append the answer to the result
$result[] = array('answer' => $answer, 'ttl' => $record['ttl']);
}
// return the result
return $result;
}
示例3: render
public function render()
{
$hostname = $this->route_matches[1];
$this->dns = dns_get_record($hostname);
$records = '';
// record ttl class type value
foreach ($this->dns as $record) {
if ($record['type'] == 'SOA') {
continue;
}
$records .= $record['host'] . ' ';
$records .= $record['ttl'] . ' ';
$records .= $record['class'] . ' ';
$records .= $record['type'] . ' ';
$records = $this->append_if_exists($records, $record, 'pri');
$records = $this->append_if_exists($records, $record, 'weight');
$records = $this->append_if_exists($records, $record, 'target');
$records = $this->append_if_exists($records, $record, 'port');
$records = $this->append_if_exists($records, $record, 'ip');
$records = $this->append_if_exists($records, $record, 'ipv6');
$records = $this->append_if_exists($records, $record, 'txt');
$records .= "\n";
}
return $records;
}
示例4: __construct
function __construct($server, $user, $pass, $db, $install = false)
{
$server = trim($server);
$user = trim($user);
$pass = trim($pass);
$db = trim($db);
if ($install) {
if (strlen($server) && $server !== 'localhost' && $server !== '127.0.0.1') {
if (!dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
notice(sprintf(t('Cannot locate DNS info for database server \'%s\''), $server));
$this->connected = false;
$this->db = null;
return;
}
}
}
if (class_exists('mysqli')) {
$this->db = @new mysqli($server, $user, $pass, $db);
if (!mysqli_connect_errno()) {
$this->connected = true;
}
} else {
$this->mysqli = false;
$this->db = mysql_connect($server, $user, $pass);
if ($this->db && mysql_select_db($db, $this->db)) {
$this->connected = true;
}
}
if (!$this->connected) {
$this->db = null;
if (!$install) {
system_unavailable();
}
}
}
示例5: validate
/**
* @param Field $field
* @return bool
*/
public function validate(Field $field)
{
if ($field->isValueEmpty() === true) {
return true;
}
$fieldValue = $field->getValue();
$emailValid = filter_var($fieldValue, FILTER_VALIDATE_EMAIL);
if ($emailValid === false) {
return false;
}
if ($this->checkMx === false) {
return true;
}
$domain = substr($fieldValue, strrpos($fieldValue, '@') + 1);
$mxRecords = array();
if (getmxrr(idn_to_ascii($domain), $mxRecords) === true) {
return true;
}
// Port 25 fallback check if there's no MX record
$aRecords = dns_get_record($domain, DNS_A);
if (count($aRecords) <= 0) {
return false;
}
$connection = @fsockopen($aRecords[0]['ip'], 25);
if (is_resource($connection) === true) {
fclose($connection);
return true;
}
return false;
}
示例6: __construct
/**
* Opens an IMAP stream
*/
public function __construct()
{
// Set Imap Timeouts
imap_timeout(IMAP_OPENTIMEOUT, 90);
imap_timeout(IMAP_READTIMEOUT, 90);
// If SSL Enabled
$ssl = Kohana::config('settings.email_ssl') == true ? "/ssl" : "";
// Do not validate certificates (TLS/SSL server)
//$novalidate = strtolower(Kohana::config('settings.email_servertype')) == "imap" ? "/novalidate-cert" : "";
$novalidate = "/novalidate-cert";
// If POP3 Disable TLS
$notls = strtolower(Kohana::config('settings.email_servertype')) == "pop3" ? "/notls" : "";
/*
More Info about above options at:
http://php.net/manual/en/function.imap-open.php
*/
$service = "{" . Kohana::config('settings.email_host') . ":" . Kohana::config('settings.email_port') . "/" . Kohana::config('settings.email_servertype') . $notls . $ssl . $novalidate . "}";
// Check if the host name is valid, if not, set imap_stream as false and return false
if (count(dns_get_record("" . Kohana::config('settings.email_host') . "")) == 0) {
$this->imap_stream = false;
return false;
}
if ($imap_stream = @imap_open($service, Kohana::config('settings.email_username'), Kohana::config('settings.email_password'))) {
$this->imap_stream = $imap_stream;
} else {
// We don't usually want to break the entire scheduler process if email settings are off
// so lets return false instead of halting the entire script with a Kohana Exception.
$this->imap_stream = false;
return false;
//throw new Kohana_Exception('imap.imap_stream_not_opened', $throwing_error);
}
}
示例7: lookup
public static function lookup($hostname)
{
self::init();
Profiler::StartTimer("DNSResolver::lookup()", 2);
$data = DataManager::singleton();
$records = $apc = NULL;
$cachekey = "dnsresolver.lookup.{$hostname}";
if (self::$cache && !empty($data->caches["apc"]) && $data->caches["apc"]["default"]->enabled) {
$apc = $data->caches["apc"]["default"];
$cached = $apc->get($cachekey);
if ($cached !== false) {
$records = unserialize($cached);
Logger::Info("DNSResolver: found '{$hostname}' in APC cache");
}
}
if ($records === NULL) {
Logger::Info("DNSResolver: Looking up '{$hostname}'");
foreach (self::$search as $suffix) {
$fqdn = $hostname . (!empty($suffix) ? "." . $suffix : "");
$records = dns_get_record($fqdn, DNS_A);
if (!empty($records)) {
break;
}
}
if (self::$cache && !empty($records) && $apc !== NULL && $apc->enabled) {
$ttl = any(self::$ttl, $records[0]["ttl"]);
$apc->set($cachekey, serialize($records), array("lifetime" => $ttl));
}
}
Profiler::StopTimer("DNSResolver::lookup()");
return $records;
}
示例8: render
public function render()
{
$query = $this->route_matches[1];
// Default to english (en).
$language = request_or_default('lang', 'en');
if (!preg_match('@^[a-z]+$@i', $language)) {
error400('`lang` should only contain letters.');
return;
}
$wmprojects = array("wikipedia", "wiktionary", "wikisource", "wikiversity", "wikibooks", "wikiquote", "wikinews");
// Default to wikipedia.org.
$project = request_or_default('proj', 'wikipedia');
if (!in_array($project, $wmprojects)) {
error400('`proj` needs to be a valid Wikimedia project.');
return;
}
if (!count(dns_get_record($language . '.' . $project . '.org'))) {
error400($language . '.' . $project . '.org is not a valid wikipedia subdomain.');
return;
}
$counts = file_get_contents('http://' . $language . '.' . $project . '.org/w/api.php?action=query&list=users' . '&usprop=editcount&format=json&ususers=' . urlencode($query));
$json_counts = json_decode($counts, true);
$json_counts = $json_counts['query']['users'];
$total_edits = 0;
foreach ($json_counts as $user) {
$total_edits += (int) $user['editcount'];
}
return $total_edits;
}
示例9: render
public function render()
{
if (filter_var($this->route_matches[1], FILTER_VALIDATE_IP)) {
// Treat it like an IP.
return gethostbyaddr($this->route_matches[1]);
} else {
// Treat it like a hostname.
if (array_key_exists('noipv6', $_REQUEST)) {
$records = dns_get_record($this->route_matches[1], DNS_A);
} else {
$records = dns_get_record($this->route_matches[1], DNS_A + DNS_AAAA);
}
$ips = array();
foreach ($records as $record) {
if (array_key_exists('ip', $record)) {
$ips[] = $record['ip'];
} elseif (array_key_exists('ipv6', $record)) {
$ips[] = $record['ipv6'];
}
}
if (!empty($ips)) {
return implode(', ', $ips);
} else {
return 'No IPs found for given hostname.';
}
}
}
示例10: isDomainInOurControl
private function isDomainInOurControl($domain)
{
if (strlen($domain) == 0) {
die("domain cannot be empty on " . __FILE__ . " at " . __LINE__);
}
$cnt = 0;
$result = dns_get_record($domain, DNS_NS, $authns, $addtl);
$isOurs = TRUE;
if (count($result) < 1) {
$this->other->Log("DNS->isDomainInOurControl", "No list of nameservers received!", false);
$isOurs = FALSE;
}
foreach ($result as $ns) {
foreach ($this->filters as $filter) {
if (preg_match($filter, $ns['target'])) {
#print("# MATCH: " . $ns['target'] . "\n");
$cnt++;
}
}
}
if (count($result) > $cnt && $cnt > 0) {
$this->other->Log("DNS->isDomainInOurControl", "List of nameservers larger than expected!", false);
} else {
if ($cnt < 2) {
$this->other->Log("DNS->isDomainInOurControl", "Nameservers did not match", false);
$isOurs = FALSE;
}
}
return $isOurs;
}
示例11: domain
/**
* 发布域名,并更新数据库
*
* @param string $domain
*
* @return \stdClass
*
* @throws \Exception\Msg
*/
public static function domain($domain)
{
$user = User::show();
$repo = Github::showDefaultBlogRepoName($user['metadata']['login']);
if ($domain) {
$dns = dns_get_record($domain, DNS_CNAME);
if (!$dns) {
throw new \Exception\Msg('指定域名没有设置CNAME记录');
}
if (count($dns) > 1) {
throw new \Exception\Msg('指定域名CNAME记录设置超过一个');
}
if ($dns[0]['target'] !== $repo) {
throw new \Exception\Msg(sprintf('指定域名CNAME错误(错误记录为:%s)', $dns[0]['target']));
}
$message = sprintf('Bind domain %s', $domain);
} else {
$message = sprintf('Remove domain');
}
$path = 'CNAME';
$result = self::publishUserRespos($path, $domain, $message);
//上传文件成功,更新数据库
if (!empty($result->content) && !empty($result->commit)) {
Blog::save(array('domain' => $domain));
}
return $result;
}
示例12: getDnsRecord
/**
* Gets a DNS record array for the target host
*/
public function getDnsRecord()
{
if (!empty($this->host) && function_exists('dns_get_record')) {
return dns_get_record($this->host);
}
return array();
}
示例13: getMxsRecords
public function getMxsRecords($domain)
{
if ($this->execEnabled()) {
return $this->getMxRecordWithDigCmd($domain);
}
return dns_get_record($domain, DNS_MX);
}
示例14: _dig
function _dig($params)
{
$user = $params['user'];
$channel = $params['channel'];
$domain = $params['domain'];
$record = $params['record'];
if (strpos($domain, '.') === false) {
$domain .= '.rockriverstar.com';
}
$output = Utils::cmdout($params);
$records = array('a' => DNS_A, 'cname' => DNS_CNAME, 'hinfo' => DNS_HINFO, 'mx' => DNS_MX, 'ns' => DNS_NS, 'ptr' => DNS_PTR, 'soa' => DNS_SOA, 'txt' => DNS_TXT, 'aaaa' => DNS_AAAA, 'srv' => DNS_SRV, 'naptr' => DNS_NAPTR, 'a6' => DNS_A6, 'all' => DNS_ALL, 'and' => DNS_ANY);
$record = $records[strtolower($record)];
$result = dns_get_record($domain, $record);
if (count($result) > 0) {
$cols = array_keys(reset($result));
$output .= '<table class="net"><tr>';
foreach ($cols as $col) {
$output .= '<th>' . $col . '</th>';
}
$output .= '</tr>';
foreach ($result as $res) {
$output .= '<tr>';
foreach ($cols as $col) {
$output .= '<td>' . $res[$col] . '</td>';
}
$output .= '</tr>';
}
$output .= '</table>';
} else {
$output .= 'No results found.';
}
//$output .= '<pre>' . print_r(,1) . '</pre>';
Status::create()->data($output)->user_id($user->id)->channel($channel)->type('message')->cssclass('net ip')->insert();
return true;
}
示例15: validEmail
function validEmail($email, $extended = false)
{
if (empty($email) or !is_string($email)) {
return false;
}
if (!preg_match('/^([a-z0-9_\'&\\.\\-\\+])+\\@(([a-z0-9\\-])+\\.)+([a-z0-9]{2,10})+$/i', $email)) {
return false;
}
if (!$extended) {
return true;
}
$config = acymailing_config();
if ($config->get('email_checkpopmailclient', false)) {
if (preg_match('#^.{1,5}@(gmail|yahoo|aol|hotmail|msn|ymail)#i', $email)) {
return false;
}
}
if ($config->get('email_checkdomain', false) and function_exists('getmxrr')) {
$domain = substr($email, strrpos($email, '@') + 1);
$mxhosts = array();
$checkDomain = getmxrr($domain, $mxhosts);
if (!empty($mxhosts) && strpos($mxhosts[0], 'hostnamedoesnotexist')) {
array_shift($mxhosts);
}
if (!$checkDomain || empty($mxhosts)) {
$dns = @dns_get_record($domain, DNS_A);
if (empty($dns)) {
return false;
}
}
}
return true;
}