/** * Selects a geographically-closest working IP address. * * @param $host * @param $port * @return string "hostname:portnumber" of selected server */ private function select_ip_address($host, $port) { // First try all servers in geographically-closest datacenter $ip_list = gethostbynamel($host); $selected_ip = ""; if ($ip_list != false) { shuffle($ip_list); foreach ($ip_list as $ip) { $socket = @stream_socket_client($ip . ":" . $port, $errno, $errstr, 0.5, STREAM_CLIENT_CONNECT); if ($socket) { $this->m_socket = $socket; $selected_ip = $ip; break; } } } // Looks like entire datacenter is down, so try our luck with one of global IPs if ($selected_ip == "") { $global_ip_list = gethostbynamel("api.global.kontagent.net"); shuffle($global_ip_list); foreach ($global_ip_list as $global_ip) { $socket = @stream_socket_client($global_ip . ":" . $port, $errno, $errstr, 0.5, STREAM_CLIENT_CONNECT); if ($socket) { $this->m_socket = $socket; $selected_ip = $global_ip; break; } } } return $selected_ip . ":" . $port; }
public function vidtrial_portal_host($val) { if (!gethostbynamel($val)) { throw new ValidationError(__("The domain you entered does not have a valid DNS entry.", VIDTRIAL_TD)); } return sanitize_text_field($val); }
/** * Resolves a hostname to one or more IP addresses. * @param string $hostname * @return array * @throw Bringit_Exception_DnsError */ public function hostsByName($hostname) { if (!($hosts = gethostbynamel($hostname))) { throw new Bringit_Exception_DnsException("Unable to resolve hostname '{$hostname}'"); } return $hosts; }
function bb2_blackhole($package) { // Only conservative lists $bb2_blackhole_lists = array( "sbl-xbl.spamhaus.org", // All around nasties // "dnsbl.sorbs.net", // Old useless data. // "list.dsbl.org", // Old useless data. // "dnsbl.ioerror.us", // Bad Behavior Blackhole ); // Things that shouldn't be blocked, from aggregate lists $bb2_blackhole_exceptions = array( "sbl-xbl.spamhaus.org" => array("127.0.0.4"), // CBL is problematic "dnsbl.sorbs.net" => array("127.0.0.10",), // Dynamic IPs only "list.dsbl.org" => array(), "dnsbl.ioerror.us" => array(), ); // Check the blackhole lists $ip = $package['ip']; $find = implode('.', array_reverse(explode('.', $ip))); foreach ($bb2_blackhole_lists as $dnsbl) { $result = gethostbynamel($find . "." . $dnsbl . "."); if (!empty($result)) { // Got a match and it isn't on the exception list $result = @array_diff($result, $bb2_blackhole_exceptions[$dnsbl]); if (!empty($result)) { return '136673cd'; } } } return false; }
function bb2_httpbl($settings, $package) { // Can't use IPv6 addresses yet if (@is_ipv6($package['ip'])) { return false; } if (@(!$settings['httpbl_key'])) { return false; } // Workaround for "MySQL server has gone away" bb2_db_query("SET @@session.wait_timeout = 90"); $find = implode('.', array_reverse(explode('.', $package['ip']))); $result = gethostbynamel($settings['httpbl_key'] . ".{$find}.dnsbl.httpbl.org."); if (!empty($result)) { $ip = explode('.', $result[0]); // Check if threat if ($ip[0] == 127 && $ip[3] & 7 && $ip[2] >= $settings['httpbl_threat'] && $ip[1] <= $settings['httpbl_maxage']) { return '2b021b1f'; } // Check if search engine if ($ip[3] == 0) { return 1; } } return false; }
/** * Run any scheduled cron tasks * * @return void */ public function displayTask() { // If the current user doesn't have access to manage the component, // try to see if their IP address is in the whtielist. // Otherwise, we stop any further code execution. if (!User::authorise('core.manage', $this->_option)) { $ip = Request::ip(); $ips = explode(',', $this->config->get('whitelist', '')); $ips = array_map('trim', $ips); if (!in_array($ip, $ips)) { $ips = gethostbynamel($_SERVER['SERVER_NAME']); if (!in_array($ip, $ips)) { $ips = gethostbynamel('localhost'); if (!in_array($ip, $ips)) { header("HTTP/1.1 404 Not Found"); exit; } } } } // Forcefully do NOT render the template // (extra processing that's not needed) Request::setVar('no_html', 1); Request::setVar('tmpl', 'component'); $now = Date::toSql(); // Get the list of jobs that should be run $results = Job::all()->whereEquals('state', 1)->where('next_run', '<=', Date::toLocal('Y-m-d H:i:s'))->whereEquals('publish_up', '0000-00-00 00:00:00', 1)->orWhere('publish_up', '<=', $now, 1)->resetDepth()->whereEquals('publish_down', '0000-00-00 00:00:00', 1)->orWhere('publish_down', '>', $now, 1)->rows(); $output = new stdClass(); $output->jobs = array(); if ($results) { foreach ($results as $job) { if ($job->get('active') || !$job->isAvailable()) { continue; } // Show related content $job->mark('start_run'); $results = Event::trigger('cron.' . $job->get('event'), array($job)); if ($results && is_array($results)) { // Set it as active in case there were multiple plugins called on // the event. This is to ensure ALL processes finished. $job->set('active', 1); $job->save(); foreach ($results as $result) { if ($result) { $job->set('active', 0); } } } $job->mark('end_run'); $job->set('last_run', Date::toLocal('Y-m-d H:i:s')); //Date::toSql()); $job->set('next_run', $job->nextRun()); $job->save(); $output->jobs[] = $job->toArray(); } } // Output any data from the jobs that ran // Largely used for debugging/monitoring purposes $this->view->set('no_html', Request::getInt('no_html', 0))->set('output', $output)->display(); }
public function applet() { $f = $this->init_module('Libs/QuickForm'); $t = $f->createElement('text', 't'); $ok = $f->createElement('submit', 'ok', __('OK')); $f->addGroup(array($t, $ok), 'w'); $f->display(); $msg =& $this->get_module_variable('msg'); if ($f->validate()) { $w = $f->exportValues(); $w = $w['w']['t']; if (ip2long($w) === false) { $ip = gethostbynamel($w); if ($ip) { $msg = ''; foreach ($ip as $i) { $msg .= $i . '<br>'; } } else { $msg = __('No such domain'); } } else { $domain = gethostbyaddr($w); if ($domain != $w) { $msg = $domain; } else { $msg = __('No such ip entry'); } } } print $msg; }
/** * Retrieve a list of licensing server IPs * * @return array */ function getHosts() { $hosts = gethostbynamel('licensing28.whmcs.com'); if ($hosts === false) { $hosts = array(); } return $hosts; }
function __construct($op = null) { $this->op = $op; $this->lnbr = $this->getOSVar('lnbr', PHP_OS); $this->beta = sha1($_SERVER["SERVER_NAME"]) === "d66185da066bb74916a24bb33d134c34e8cf1073" ? true : false; $this->clear_detect(); \frdl\webfan\App::God(false)->addFunc('getOSName', function () { return PHP_OS; }); \frdl\webfan\App::God(false)->addFunc('getServerIp', function ($all = true) { $i = gethostbynamel($_SERVER['SERVER_NAME']); if ($all === false) { return isset($i['ips'][0]) ? $i['ips'][0] : '0.0.0.0'; } return $i; }); \frdl\webfan\App::God(false)->addFunc('getBaseDir', function () { $open_basedir = ini_get('open_basedir'); if (!is_string($open_basedir) || trim($open_basedir) === '') { return realpath($_SERVER['DOCUMENT_ROOT'] . \frdl\webfan\App::DS . '..' . \frdl\webfan\App::DS) . \frdl\webfan\App::DS; } else { $basedir = explode(':', $open_basedir); $basedir = trim($basedir[0]); return $basedir; } }); \frdl\webfan\App::God(false)->addFunc('removeEvalFromFilename', function () { $args = func_get_args(); return str_replace(' : eval()\'d code', '', preg_replace("/(\\([0-9]+\\))/", "", $args[0][0])); }); $this->str = array(); $this->str['en'] = array('English', array('__MAINTENANCE__' => '<span class="webfan-red">Our Install-Server is in maintenance mode.</span> Please try again later: <a href="http://www.webfan.de/install/">http://www.webfan.de/install/</a>', '__APPS__' => 'Applications', '__INSTALLATIONS__' => 'Installations', '__SETTINGS__' => 'Settings', '__INSTALL__' => 'install', '__INSTALL_NOW__' => 'install now', '__INSTALL_HERE__' => 'Install HERE!', '__IS_NOT_WRITABLE__' => 'is not writable', '__DOWNLOAD_FAILED__' => 'Download failed', '__CANNOT_WRITE_FILE__' => 'Cannot write file', '__CANNOT_UNZIP_FILE__' => 'Cannot unzip file', '__ACCEPT_LICENSE__' => 'Accept license', '__LANGUAGE__' => 'Language', '__VERSION_UNAVAILABLE__' => 'The selected version is not available', '__ERROR__' => 'Error', '__HINT_DEL_FILE__' => 'You should delete this file when done!\\nTo do so click the red button at bottom!', '__RECOMMENDED__' => 'recommended', '__THIS_FILE__' => 'This file', '__TEST_ONLY__' => 'For testing only', '__INCOMPLETE_OR_BROKEN__' => 'Incomplete or broken', '__SURE_BACKUP__' => 'sure/backup', '__CHECK_SURE__' => 'not confirmed', '__REQUIRED_PHP_VERSION_FAILED_1__' => 'Your php version does not apply to the requirements of the requested software. You need <strong>PHP Version</strong> ' . htmlentities('=>') . ' ', '__INSTALL_TEMP_DIR__' => 'Temp-Dir', '__NO_PRAGMAMX_FOUND_IND_DIR__' => 'No PragmaMx installation found in the given directory', '__CHECKSUM_INVALID__' => 'Invalid checksum', '__REQUIRED_BY_WEBFAN_PMX_MODULES__' => 'required by the Webfan PragmaMx Modules')); $this->str['de'] = array('Deutsch', array('__MAINTENANCE__' => '<span class="webfan-red">Der Install-Server wird derzeit gewartet.</span> Bitte etwas später nochmal probieren: <a href="http://www.webfan.de/install/">http://www.webfan.de/install/</a>', '__APPS__' => 'Anwendungen', '__INSTALLATIONS__' => 'Installationen', '__SETTINGS__' => 'Einstellungen', '__INSTALL__' => 'installieren', '__INSTALL_NOW__' => 'jetzt installieren', '__INSTALL_HERE__' => 'HIER installieren', '__IS_NOT_WRITABLE__' => 'ist nicht beschreibbar', '__DOWNLOAD_FAILED__' => 'Download fehlgeschlagen', '__CANNOT_WRITE_FILE__' => 'Kann Datei nicht schreiben', '__CANNOT_UNZIP_FILE__' => 'Kann Datei nicht entpacken', '__ACCEPT_LICENSE__' => 'Lizenz akzeptieren', '__LANGUAGE__' => 'Sprache', '__VERSION_UNAVAILABLE__' => 'Die ausgewählte Version ist nicht verfügbar', '__ERROR__' => 'Fehler', '__HINT_DEL_FILE__' => 'Sie sollten diese Datei löschen wenn Sie fertig sind!\\nKlicken Sie hierzu auf den roten Button ganz unten!', '__RECOMMENDED__' => 'empfohlen', '__THIS_FILE__' => 'Diese Datei', '__TEST_ONLY__' => 'Nur für Testzwecke', '__INCOMPLETE_OR_BROKEN__' => 'Unvollständig oder defekt', '__SURE_BACKUP__' => 'sicher/Backup', '__CHECK_SURE__' => 'nicht bestätigt', '__REQUIRED_PHP_VERSION_FAILED_1__' => 'Ihre php Version genügt nicht den Ansprüchen der angeforderten Software. Sie benötigen <strong>PHP Version</strong> ' . htmlentities('=>') . ' ', '__INSTALL_TEMP_DIR__' => 'Temp-Dir', '__NO_PRAGMAMX_FOUND_IND_DIR__' => 'Keine PragmaMx Installation im angegebenen Verzeichnis gefunden', '__CHECKSUM_INVALID__' => 'Ungültige Prüfsumme', '__REQUIRED_BY_WEBFAN_PMX_MODULES__' => 'wird zur Installation und Betrieb der Webfan Module für das PragmaMx CMS benötigt')); $this->str['fr'] = array('French', array('__MAINTENANCE__' => '<span class="webfan-red">Notre serveur d\'installation est en cours de maintenance.</span> Merci de réessayer plus tard: <a href="http://www.webfan.de/install/">http://www.webfan.de/install/</a>', '__APPS__' => 'Applications', '__INSTALLATIONS__' => 'Installations', '__SETTINGS__' => 'Paramètres', '__INSTALL__' => 'installer', '__INSTALL_NOW__' => 'installer maintenant', '__INSTALL_HERE__' => 'Installer ici !', '__IS_NOT_WRITABLE__' => 'n\'est pas inscriptible', '__DOWNLOAD_FAILED__' => 'Téléchargement échoué', '__CANNOT_WRITE_FILE__' => 'Impossible d\'écrire le fichier', '__CANNOT_UNZIP_FILE__' => 'Impossible de décompresser le fichier', '__ACCEPT_LICENSE__' => 'Accepter la license', '__LANGUAGE__' => 'Langage', '__VERSION_UNAVAILABLE__' => 'La version choise n\'est pas disponible', '__ERROR__' => 'Erreur', '__HINT_DEL_FILE__' => 'Vous devriez supprimer ce fichier un fois terminé !\\nPour le faire cliquer sur le bouton rouge au dessous!', '__RECOMMENDED__' => 'recommendé', '__THIS_FILE__' => 'Ce fichier', '__TEST_ONLY__' => 'Seulement pour des test', '__INCOMPLETE_OR_BROKEN__' => 'Incomplet ou cassé', '__SURE_BACKUP__' => 'sauver/sauvegarder', '__CHECK_SURE__' => 'non confirmé', '__REQUIRED_PHP_VERSION_FAILED_1__' => 'Votre version de php ne correspond pas à celle requise par le logiciel. Vous avez besoin de la <strong>Version de PHP</strong> ' . htmlentities('=>') . ' ', '__INSTALL_TEMP_DIR__' => 'Dossier temporaire', '__NO_PRAGMAMX_FOUND_IND_DIR__' => 'Aucune installation de PragmaMx n\'a été trouvé de le répertoire spécifié', '__CHECKSUM_INVALID__' => 'Checksum invalide', '__REQUIRED_BY_WEBFAN_PMX_MODULES__' => 'Requis pour les modules PragmaMx WEBFAN')); $this->forms = array(); $this->forms[self::GROUP_CURRENT] = null; $this->forms[self::GROUP_APPS] = array(self::APP_PMX => array('render_func' => 'form_pmx', 'flushed' => false), self::APP_WEBDOF => array('render_func' => 'form_app_webdof', 'flushed' => false)); if (!isset($_SESSION[self::SESSKEY])) { $_SESSION[self::SESSKEY] = array(); } if (isset($_SESSION[self::SESSKEY]['op'])) { $this->op =& $_SESSION[self::SESSKEY]['op']; } else { $_SESSION[self::SESSKEY]['op'] =& $this->op; } $_SESSION[self::SESSKEY]['lang'] = isset($_SESSION[self::SESSKEY]['lang']) ? $_SESSION[self::SESSKEY]['lang'] : 'en'; if (isset($_REQUEST['lang']) && isset($this->str[$_REQUEST['lang']])) { $_SESSION[self::SESSKEY]['lang'] = strip_tags($_REQUEST['lang']); } $this->lang =& $_SESSION[self::SESSKEY]['lang']; $this->dir_install_temp = isset($_SESSION[self::SESSKEY]['dir_install_temp']) ? $_SESSION[self::SESSKEY]['dir_install_temp'] : __DIR__ . \frdl\webfan\App::DS; if (!isset($_SESSION[self::SESSKEY]['repositories'])) { Loader::repository('frdl'); } $_SESSION[self::SESSKEY]['repositories'] = isset($_SESSION[self::SESSKEY]['repositories']) ? $_SESSION[self::SESSKEY]['repositories'] : array('webfan' => array('name' => 'Webfan Installer (webdof)'), 'frdl' => array('name' => 'frdl (Application Composer)')); $this->katalog(); }
static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model) { $o = XenForo_Application::getOptions(); if ($o->TPUDetectSpamRegTORScore != 0) { // Only IPv4 supported if (filter_var($user['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) == FALSE) { return; } $srvIp = array(); if ($o->TPUDetectSpamRegSrvIp != '') { $list = explode(',', $o->TPUDetectSpamRegSrvIp); foreach ($list as $entry) { $entry = trim($entry); if ($entry != '') { $hosts = gethostbynamel($entry); if (is_array($hosts)) { foreach ($hosts as $ip) { // Only IPv4 supported if (filter_var($user['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $srvIp[] = $ip; } } } } } } if (!$srvIp) { if (isset($_SERVER['SERVER_ADDR'])) { $srvIp[] = $_SERVER['SERVER_ADDR']; } elseif (isset($_SERVER['LOCAL_ADDR'])) { $srvIp[] = $_SERVER['LOCAL_ADDR']; } } $srvIp = array_unique($srvIp); if (!$srvIp) { $model->logScore('Could not get server IP address for TOR detection module', 0); return; } $user_ip = self::reverseIP($user['ip']); $portsToCheck = array(80, 443); // Check both HTTP and HTTPS foreach ($srvIp as $ip) { foreach ($portsToCheck as $port) { $q = sprintf('%s.%s.%s.ip-port.exitlist.torproject.org', $user_ip, $port, self::reverseIP($ip)); if (gethostbyname($q) == '127.0.0.2') { $model->logScore('tpu_detectspamreg_tor_fail', $o->TPUDetectSpamRegTORScore); $score['points'] += $o->TPUDetectSpamRegTORScore; return; } } } if ($debug) { $model->logScore('tpu_detectspamreg_tor_ok', 0); } } }
function socket_connect_hostname($socket, $hostname, $port) { $ips = gethostbynamel($hostname); foreach ($ips as $ip) { if (socket_connect($socket, $ip, $port)) { return TRUE; } } return FALSE; }
/** * Name to IP list, * get all ip numbers given a certain domain or host $name. * * @param $name being a hostname * * @return array of ip numbers */ public function nametoipl($name = '') { if ('true' == Configure::read('MISP.dns')) { if (!($ips = gethostbynamel($name))) { $ips = array(); } } else { $ips = array(); } return $ips; }
/** * Checks if a host as a valid list of IPs * @param $host * @throws InvalidHostException */ protected function checkHost($host) { $disallowed = array('https://', 'http://'); foreach ($disallowed as $d) { if (strpos($host, $d) === 0) { $host = str_replace($d, '', $host); } } if (false === gethostbynamel($host)) { throw new InvalidHostException($host); } }
/** * Checks if the server specified in the url exists. * * @param $url url to check * @return true, if the server exists; false otherwise */ function hostExists($url) { if (strpos($url, '/') === false) { $server = $url; } else { $server = @parse_url($url, PHP_URL_HOST); } if (!$server) { return false; } return !!gethostbynamel($server); }
/** * Display a list of latest whiteboard entries * * @return void */ public function displayTask() { if (!User::authorise('core.manage', $this->_option)) { $ip = Request::ip(); $ips = explode(',', $this->config->get('whitelist', '')); $ips = array_map('trim', $ips); if (!in_array($ip, $ips)) { $ips = gethostbynamel($_SERVER['SERVER_NAME']); if (!in_array($ip, $ips)) { $ips = gethostbynamel('localhost'); if (!in_array($ip, $ips)) { header("HTTP/1.1 404 Not Found"); exit; } } } } Request::setVar('no_html', 1); Request::setVar('tmpl', 'component'); $now = Date::toSql(); $results = Job::all()->whereEquals('state', 1)->where('next_run', '<=', Date::toLocal('Y-m-d H:i:s'))->whereEquals('publish_up', '0000-00-00 00:00:00', 1)->orWhere('publish_up', '<=', $now, 1)->resetDepth()->whereEquals('publish_down', '0000-00-00 00:00:00', 1)->orWhere('publish_down', '>', $now, 1)->rows(); $output = new stdClass(); $output->jobs = array(); if ($results) { foreach ($results as $job) { if ($job->get('active') || !$job->isAvailable()) { continue; } // Show related content $job->mark('start_run'); $results = Event::trigger('cron.' . $job->get('event'), array($job)); if ($results && is_array($results)) { // Set it as active in case there were multiple plugins called on // the event. This is to ensure ALL processes finished. $job->set('active', 1); $job->save(); foreach ($results as $result) { if ($result) { $job->set('active', 0); } } } $job->mark('end_run'); $job->set('last_run', Date::toLocal('Y-m-d H:i:s')); //Date::toSql()); $job->set('next_run', $job->nextRun()); $job->save(); $output->jobs[] = $job->toArray(); } } $this->view->set('no_html', Request::getInt('no_html', 0))->set('output', $output)->display(); }
public function isValidHost($hostname) { $ips = gethostbynamel($hostname); if (is_array($ips) && count($ips) > 0) { if (!function_exists('checkdnsrr')) { return true; } if (!checkdnsrr($hostname, 'MX')) { return false; } } return true; return false; }
function checkAccess($neighbour) { $url = $neighbour->getUrl(); if (!$url) { return "No url found for neighbour node"; } $parsed = parse_url($url); $allowedIPs = gethostbynamel($parsed['host']); $ip = getenv("REMOTE_ADDR"); if (!in_array($ip, $allowedIPs)) { logError(getenv('REMOTE_HOST') . " XML-RPC access denied"); return "this IP is not from neighbour " . $neighbour->get('node_id'); } }
function bb2_httpbl_lookup($ip) { // NB: Many of these are defunct $engines = array(1 => "AltaVista", 2 => "Teoma/Ask Crawler", 3 => "Baidu Spide", 4 => "Excite", 5 => "Googlebot", 6 => "Looksmart", 7 => "Lycos", 8 => "msnbot", 9 => "Yahoo! Slurp", 10 => "Twiceler", 11 => "Infoseek", 12 => "Minor Search Engine"); $settings = bb2_read_settings(); $httpbl_key = $settings['httpbl_key']; if (!$httpbl_key) { return false; } $r = $_SESSION['httpbl'][$ip]; $d = ""; if (!$r) { // Lookup $find = implode('.', array_reverse(explode('.', $ip))); $result = gethostbynamel("{$httpbl_key}.{$find}.dnsbl.httpbl.org."); if (!empty($result)) { $r = $result[0]; $_SESSION['httpbl'][$ip] = $r; } } if ($r) { // Interpret $ip = explode('.', $r); if ($ip[0] == 127) { if ($ip[3] == 0) { if ($engines[$ip[2]]) { $d .= $engines[$ip[2]]; } else { $d .= "Search engine {$ip[2]}<br/>\n"; } } if ($ip[3] & 1) { $d .= "Suspicious<br/>\n"; } if ($ip[3] & 2) { $d .= "Harvester<br/>\n"; } if ($ip[3] & 4) { $d .= "Comment Spammer<br/>\n"; } if ($ip[3] & 7) { $d .= "Threat level {$ip[2]}<br/>\n"; } if ($ip[3] > 0) { $d .= "Age {$ip[1]} days<br/>\n"; } } } return $d; }
public static function dns_check($addr, $host) { if ($addr != $host) { $addrs = gethostbynamel($host . '.'); if (isset($addrs) && is_array($addrs)) { foreach ($addrs as $host_addr) { if ($addr == $host_addr) { return 1; } } } return -1; } return 0; }
function bb2_httpbl($settings, $package) { if (!$settings['httpbl_key']) { return false; } $find = implode('.', array_reverse(explode('.', $package['ip']))); $result = gethostbynamel($settings['httpbl_key'] . ".{$find}.dnsbl.httpbl.org."); if (!empty($result)) { $ip = explode('.', $result[0]); if ($ip[0] == 127 && $ip[3] & 7 && $ip[2] >= $settings['httpbl_threat'] && $ip[1] >= $settings['httpbl_maxage']) { return '2b021b1f'; } } return false; }
/** * Check dns resolving for DB_HOST */ function check_dns() { if (filter_var(DB_HOST, FILTER_VALIDATE_IP) === false) { $ips = gethostbynamel(DB_HOST); if (empty($ips)) { debug_msg('\'' . DB_HOST . '\' dns query doesn\'t resolve to any ip address.'); } else { debug_msg(DB_HOST . ' dns query resolves to: ' . implode(',', $ips)); } } else { // If database is just plain ip address dns doesn't matter $ips = array(DB_HOST); } return $ips; }
public static function get($ip) { if (self::is_ipv6($ip)) { return null; } $find = implode('.', array_reverse(explode('.', $ip))); $query = self::$api_key . ".{$find}.dnsbl.httpbl.org"; $result = gethostbynamel($query); if (!empty($result)) { $ip = explode('.', $result[0]); if ($ip[0] == 127) { return array('age' => $ip[1], 'threat' => $ip[2], 'type' => $ip[3]); } } return null; }
/** * @param string $socketAddress * * @return bool */ public static function isLocalAddress($socketAddress) { static $localAddresses = null; if (self::isUnixAddress($socketAddress)) { return true; } if ($localAddresses === null) { $localAddresses = array_merge(['0.0.0.0', '127.0.0.1', '[::]', '[::1]'], gethostbynamel(gethostname())); } foreach ($localAddresses as $address) { if (strpos($socketAddress, $address) !== false) { return true; } } return false; }
function bb2_roundtripdns($ip, $domain) { if (@is_ipv6($ip)) { return $ip; } $host = gethostbyaddr($ip); $host_result = strpos(strrev($host), strrev($domain)); if ($host_result === false || $host_result > 0) { return false; } $addrs = gethostbynamel($host); if (in_array($ip, $addrs)) { return true; } return false; }
function checkAccess($url, $nodeId) { if (!$url) { return "No url found for neighbour node"; } $parsed = parse_url($url); $allowedIPs = gethostbynamel($parsed['host']); if (count($allowedIPs) == 0) { logError("DNS does not work, cannor resolve host name!"); } $ip = getenv("REMOTE_ADDR"); debug("allowedIPs", $allowedIPs); if (!in_array($ip, $allowedIPs)) { logError(getenv('REMOTE_HOST') . " XML-RPC access denied"); return "this IP is not from neighbour " . $nodeId; } }
/** * @param string $mail * @param bool $isDnsCheck DNSをチェックするかどうかのフラグ * @return bool * @access public */ public function mail($mail, $isDnsCheck = false) { if (!preg_match('/^[a-zA-Z0-9_]?[a-zA-Z0-9._+-]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]{2,4}$/', $mail)) { return false; } if (!$isDnsCheck) { return true; } if (!function_exists('checkdnsrr')) { return true; } list($user, $domain) = explode('@', $mail, 2); if (!checkdnsrr($domain, 'MX') && !gethostbynamel($domain)) { // If not exists MX recode then MX is host. (RFC.2821 return false; } return true; }
public static function verifyCrawlerPTR($hostPattern, $IP) { global $wpdb; $table = $wpdb->base_prefix . 'wfCrawlers'; $db = new wfDB(); $IPn = wfUtils::inet_aton($IP); $status = $db->querySingle("select status from {$table} where IP=%s and patternSig=UNHEX(MD5('%s')) and lastUpdate > unix_timestamp() - %d", $IPn, $hostPattern, WORDFENCE_CRAWLER_VERIFY_CACHE_TIME); if ($status) { if ($status == 'verified') { return true; } else { return false; } } $wfLog = new wfLog(wfConfig::get('apiKey'), wfUtils::getWPVersion()); $host = wfUtils::reverseLookup($IP); if (!$host) { $db->queryWrite("insert into {$table} (IP, patternSig, status, lastUpdate, PTR) values (%s, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $IPn, $hostPattern, 'noPTR', '', 'noPTR', ''); return false; } if (preg_match($hostPattern, $host)) { $resultIPs = gethostbynamel($host); $addrsMatch = false; foreach ($resultIPs as $resultIP) { if ($resultIP == $IP) { $addrsMatch = true; break; } } if ($addrsMatch) { $db->queryWrite("insert into {$table} (IP, patternSig, status, lastUpdate, PTR) values (%s, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $IPn, $hostPattern, 'verified', $host, 'verified', $host); return true; } else { $db->queryWrite("insert into {$table} (IP, patternSig, status, lastUpdate, PTR) values (%s, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $IPn, $hostPattern, 'fwdFail', $host, 'fwdFail', $host); return false; } } else { $db->queryWrite("insert into {$table} (IP, patternSig, status, lastUpdate, PTR) values (%s, UNHEX(MD5('%s')), '%s', unix_timestamp(), '%s') ON DUPLICATE KEY UPDATE status='%s', lastUpdate=unix_timestamp(), PTR='%s'", $IPn, $hostPattern, 'badPTR', $host, 'badPTR', $host); return false; } }
public function email($check, $deep = false, $regex = null) { $this->reset(); $this->check = $check; $this->regex = $regex; $this->deep = $deep; if (is_null($this->regex)) { $this->regex = "/^[a-z0-9!#\$%&'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+\\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+(?:[a-z]{2,4}|museum|travel)\$/i"; } $return = $this->check(); if ($this->deep === false || $this->deep === null) { return $return; } if ($return === true && preg_match('/@([a-z0-9][a-z0-9\\.\\-]{0,63}\\.([a-z]*))/', $this->check, $regs)) { $host = gethostbynamel($regs[1]); if (is_array($host)) { return true; } } return false; }
/** * Creates a new server instance with the given address and port * * @param string $address Either an IP address, a DNS name or one of them * combined with the port number. If a port number is given, e.g. * 'server.example.com:27016' it will override the second argument. * @param int $port The port the server is listening on * @see initSocket() * @throws SteamCondenserException if an host name cannot be resolved */ public function __construct($address, $port = null) { $address = strval($address); if (strpos($address, ':') !== false) { $address = explode(':', $address, 2); $port = $address[1]; $address = $address[0]; } $this->ipAddresses = []; $this->ipIndex = 0; $this->port = intval($port); $addresses = gethostbynamel($address); if (empty($addresses)) { throw new SteamCondenserException("Cannot resolve {$address}"); } foreach ($addresses as $address) { $this->ipAddresses[] = $address; } $this->ipAddress = $this->ipAddresses[0]; $this->initSocket(); }
public function __construct($logger) { $this->_logger = $logger; if (Settings::Get('system.nameservers') != '') { $nameservers = explode(',', Settings::Get('system.nameservers')); foreach ($nameservers as $nameserver) { $nameserver = trim($nameserver); // DNS servers might be multi homed; allow transfer from all ip // addresses of the DNS server $nameserver_ips = gethostbynamel($nameserver); // append dot to hostname if (substr($nameserver, -1, 1) != '.') { $nameserver .= '.'; } // ignore invalid responses if (!is_array($nameserver_ips)) { // act like gethostbyname() and return unmodified hostname on error $nameserver_ips = array($nameserver); } $this->_ns[] = array('hostname' => $nameserver, 'ips' => $nameserver_ips); } } if (Settings::Get('system.mxservers') != '') { $mxservers = explode(',', Settings::Get('system.mxservers')); foreach ($mxservers as $mxserver) { if (substr($mxserver, -1, 1) != '.') { $mxserver .= '.'; } $this->_mx[] = $mxserver; } } // AXFR server #100 if (Settings::Get('system.axfrservers') != '') { $axfrservers = explode(',', Settings::Get('system.axfrservers')); foreach ($axfrservers as $axfrserver) { $this->_axfr[] = trim($axfrserver); } } }