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; } }
/** * 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; }
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; }
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(); } } }
/** * @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; }
/** * 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); } }
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; }
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; }
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.'; } } }
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; }
/** * 发布域名,并更新数据库 * * @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; }
/** * 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(); }
public function getMxsRecords($domain) { if ($this->execEnabled()) { return $this->getMxRecordWithDigCmd($domain); } return dns_get_record($domain, DNS_MX); }
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; }
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; }
/** * 檢查IP是否被列為Spam來源 * @param String $ipAddress IP位址 * @return Array 檢查結果 */ function _ipSpamCheck($ipAddress) { $revip = implode(".", array_reverse(explode(".", $ipAddress, 4), false)); /** * 使用的SPAM檢查服務 * Abuseat: http://www.abuseat.org/faq.html * Barracuda: http://www.barracudacentral.org/rbl/how-to-use * Sorbs: http://www.sorbs.net/general/using.shtml * Spamcop: https://www.spamcop.net/fom-serve/cache/291.html * Spamhaus: https://www.spamhaus.org/faq/section/DNSBL%2520Usage#202 * Surbl: http://www.surbl.org/lists * Uribl: http://uribl.com/about.shtml#info */ $blacklists = array(array('Abuseat', 'cbl.abuseat.org'), array('Barracuda', 'b.barracudacentral.org'), array('Sorbs', 'dnsbl.sorbs.net'), array('Spamcop', 'bl.spamcop.net'), array('Spamhaus', 'zen.spamhaus.org'), array('Surbl', 'multi.surbl.org'), array('Uribl', 'black.uribl.com')); $checkSerial = 0; foreach ($blacklists as $key => $val) { $checkIP = $revip . '.' . $val[1]; $spamCheckRes[$checkSerial]['serverName'] = $val[0]; $records = dns_get_record($checkIP, DNS_A); if (count($records) > 0) { $spamCheckRes[$checkSerial]['result'] = true; } else { $spamCheckRes[$checkSerial]['result'] = false; } $checkSerial++; } return $spamCheckRes; }
function MailNotify($msg, $subject) { global $config_values; $emailAddress = $config_values['Settings']['Email Address']; if (!empty($emailAddress)) { $email = new PHPMailer(); if (function_exists(dns_get_record) && dns_get_record(gethostname) && dns_get_record(gethostname())) { $email->From = "TW-X@" . gethostname(); } else { $email->From = "*****@*****.**"; } $email->FromName = "TorrentWatch-X"; $email->AddAddress("{$emailAddress}"); $email->Subject = $subject; $email->Host = $config_values['Settings']['SMTP Server']; $email->Mailer = "smtp"; $mail = @file_get_contents("templates/email.tpl"); $mail = str_replace('[MSG]', $msg, $mail); if (empty($mail)) { $mail = $msg; } $email->Body = $mail; if (!$email->Send()) { _debug("Mailer Error: " . $mail->ErrorInfo . "\n"); } else { _debug("Mail sent to {$emailAddress} with subject: {$subject} via: " . $config_values['Settings']['SMTP Server'] . "\n"); } } }
protected static function discoverLdapServers($zone) { $result = array(); // search for LDAPS servers $ldapServers = dns_get_record('_ldaps._tcp.' . $zone, DNS_SRV); uksort($ldapServers, array('LdapEnvironment', 'compareDnsRecordPriority')); foreach ($ldapServers as $server) { $tmp = new stdClass(); $tmp->hostname = $server['target']; $tmp->port = $server['port']; $tmp->isSslPort = true; $result[] = $tmp; } // search for non-SSL LDAP servers $ldapServers = dns_get_record('_ldap._tcp.' . $zone, DNS_SRV); uksort($ldapServers, array('LdapEnvironment', 'compareDnsRecordPriority')); foreach ($ldapServers as $server) { $tmp = new stdClass(); $tmp->hostname = $server['target']; $tmp->port = $server['port']; $tmp->isSslPort = false; $result[] = $tmp; } return $result; }
/** * IP of the Host * * @return void */ protected function ip() { if (PSI_USE_VHOST === true) { if ((($result = getenv('SERVER_ADDR')) || ($result = getenv('LOCAL_ADDR'))) && !strstr($result, '.') && strstr($result, ':')) { //is IPv6, quick version of preg_match('/\(([[0-9A-Fa-f\:]+)\)/', $result) $dnsrec = dns_get_record($this->sys->getHostname(), DNS_AAAA); if (isset($dnsrec[0]['ipv6'])) { //is DNS IPv6 record $this->sys->setIp($dnsrec[0]['ipv6']); //from DNS (avoid IPv6 NAT translation) } else { $this->sys->setIp(preg_replace('/^::ffff:/i', '', $result)); //from SERVER_ADDR or LOCAL_ADDR } } else { $this->sys->setIp(gethostbyname($this->sys->getHostname())); //IPv4 only } } else { if (($result = getenv('SERVER_ADDR')) || ($result = getenv('LOCAL_ADDR'))) { $this->sys->setIp(preg_replace('/^::ffff:/i', '', $result)); } else { $this->sys->setIp(gethostbyname($this->sys->getHostname())); } } }
function _openid_discover_email($email, &$error = null) { if (preg_match('/^[a-z0-9\\!#\\$%&\'\\*\\+\\-\\/\\=\\?\\^_`\\{\\|\\}~\\.]+@([a-z0-9\\.\\-]+)$/i', $email, $matches) && ($dns_records = dns_get_record($matches[1], DNS_MX)) && isset($dns_records[0]) && preg_match('/\\.googlemail\\.com$|\\.google\\.com$/i', $dns_records[0]['target'])) { return 'https://www.google.com/accounts/o8/id'; } else { return $email; } }
/** * Get the IPv6 address of the given hostname. * * @param $hostname The hostname to resolve * * @return string|null The IPv6 address of the given hostname or null, when no entry exists. */ public static function ipv6($hostname) { $records = dns_get_record($hostname, DNS_AAAA); if ($records !== false && count($records) > 0) { return $records[0]['ip']; } return null; }
/** * @param $email * * @return mixed */ private function domainExists($email) { list($user, $domain) = explode('@', $email); $arr = dns_get_record($domain, DNS_MX); if ($arr[0]['host'] == $domain && !empty($arr[0]['target'])) { return $arr[0]['target']; } }
public function dnsRecords($host = '', $type = 'any', $raw = false) { if (!is_string($host)) { return Error::set('Error', 'stringParameter', '1.(host)'); } $dns = dns_get_record($this->cleanHttp($host), Convert::toConstant($type, 'DNS_'), $auth, $add, $raw); return (object) array('records' => $dns, 'authns' => $auth, 'addtl' => $add); }
public static function lookUp($hostName, $type = RecordType::ANY, $withAuthEntries = false, $withAdditionalLookups = false) { $authNs = null; $additionalLookups = null; $result = null; if ($withAdditionalLookups) { $result = @dns_get_record($hostName, $type, $authNs, $additionalLookups); } else { if ($withAuthEntries) { $result = @dns_get_record($hostName, $type, $authNs); } else { $result = @dns_get_record($hostName, $type); } } if (!$result) { throw new Exception("Failed to get DNS records for {$hostName}, maybe there is no DNS available"); } foreach ($result as $record) { $type = RecordType::getValue($record['type']); switch ($type) { case RecordType::A6: (yield new A6($record['host'], $record['chain'], Address::fromString($record['ipv6']), $record['masklen'], $record['ttl'])); break; case RecordType::AAAA: (yield new Aaaa($record['host'], Address::fromString($record['ipv6']), $record['ttl'])); break; case RecordType::A: (yield new A($record['host'], Address::fromString($record['ip']), $record['ttl'])); break; case RecordType::CNAME: (yield new Cname($record['host'], $record['target'], $record['ttl'])); break; case RecordType::HINFO: (yield new Hinfo($record['host'], $record['cpu'], $record['os'], $record['ttl'])); break; case RecordType::MX: (yield new Mx($record['host'], $record['target'], $record['pri'], $record['ttl'])); break; case RecordType::NS: (yield new Ns($record['host'], $record['target'], $record['ttl'])); break; case RecordType::PTR: (yield new Ptr($record['host'], $record['target'], $record['ttl'])); break; //TODO: SRV record isn't fetched //TODO: SRV record isn't fetched case RecordType::SOA: (yield new Soa($record['host'], $record['mname'], $record['rname'], $record['serial'], $record['refresh'], $record['retry'], $record['expire'], $record['minimum-ttl'], $record['ttl'])); break; case RecordType::TXT: (yield new Txt($record['host'], $record['txt'], $record['ttl'])); break; default: (yield new Record($record['host'], $type, $record['ttl'])); break; } } }
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; } } } $object = new stdClass(); $object->IP = $this->getIP(); $object->emailAddress = $email; if ($config->get('email_botscout', false)) { $botscoutClass = new acybotscout(); $botscoutClass->apiKey = $config->get('email_botscout_key'); if (!$botscoutClass->getInfo($object)) { return false; } } if ($config->get('email_stopforumspam', false)) { $email_stopforumspam = new acystopforumspam(); if (!$email_stopforumspam->getInfo($object)) { return false; } } if ($config->get('email_iptimecheck', 0)) { $lapseTime = time() - 7200; $db = JFactory::getDBO(); $db->setQuery('SELECT COUNT(*) FROM #__acymailing_subscriber WHERE created > ' . intval($lapseTime) . ' AND ip = ' . $db->Quote($object->IP)); $nbUsers = $db->loadResult(); if ($nbUsers >= 3) { return false; } } return true; }
function gethostbyaddrl($ip) { $rrs = dns_get_record(implode('.', array_reverse(explode('.', $ip))) . '.in-addr.arpa.', DNS_PTR); $revnames = array(); foreach ($rrs as $rr) { $revnames[] = $rr['target']; } return count($revnames) ? $revnames : FALSE; }
public function resolve($name, $type) { $record = dns_get_record($name, $type); $mapped = array(); foreach ($record as $address) { $mapped[] = Url::fromHostAndPort($address['target'], $address['port']); } return $mapped; }
function setUp() { if (!extension_loaded('geoip')) { skip('geoip extension is required.'); } if (!dns_get_record('www.hinet.net')) { skip('networking is required.'); } }
/** * DNS Lookup * @param $hostname * @return array * @throws Exception */ protected function dns_lookup($hostname, $type = DNS_A) { $service_array = dns_get_record($hostname, $type); if (count($service_array) < 1) { throw new Exception('No Services Found'); // @todo Update } return $service_array; }
function get_host($ip) { $ptr = implode(".", array_reverse(explode(".", $ip))) . ".in-addr.arpa"; $host = dns_get_record($ptr, DNS_PTR); if ($host == null) { return $ip; } else { return $host[0]['target']; } }