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


PHP gethostbyname函数代码示例

本文整理汇总了PHP中gethostbyname函数的典型用法代码示例。如果您正苦于以下问题:PHP gethostbyname函数的具体用法?PHP gethostbyname怎么用?PHP gethostbyname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: index

 public function index()
 {
     $os = explode(' ', php_uname());
     $mysql_support = function_exists('mysql_close') ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $register_globals = get_cfg_var("register_globals") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $enable_dl = get_cfg_var("enable_dl") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $allow_url_fopen = get_cfg_var("allow_url_fopen") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $display_errors = get_cfg_var("display_errors") ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $session_support = function_exists('session_start') ? '<font color="green">√</font>' : '<font color="red">×</font>';
     $config['server_name'] = $_SERVER['SERVER_NAME'];
     $config['server_ip'] = @gethostbyname($_SERVER['SERVER_NAME']);
     $config['server_time'] = date("Y年n月j日 H:i:s");
     $config['os'] = $os[0];
     $config['os_core'] = $os[2];
     $config['server_root'] = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
     $config['server_engine'] = $_SERVER['SERVER_SOFTWARE'];
     $config['server_port'] = $_SERVER['SERVER_PORT'];
     $config['php_version'] = PHP_VERSION;
     $config['php_run_type'] = strtoupper(php_sapi_name());
     $config['mysql_support'] = $mysql_support;
     $config['register_globals'] = $register_globals;
     $config['allow_url_fopen'] = $allow_url_fopen;
     $config['display_errors'] = $display_errors;
     $config['enable_dl'] = $enable_dl;
     $config['memory_limit'] = get_cfg_var("memory_limit");
     $config['post_max_size'] = get_cfg_var("post_max_size");
     $config['upload_max_filesize'] = get_cfg_var("upload_max_filesize");
     $config['max_execution_time'] = get_cfg_var("max_execution_time");
     $config['session_support'] = $session_support;
     $this->config_arr = $config;
     $this->display();
 }
开发者ID:redisck,项目名称:xiangmu,代码行数:32,代码来源:ConfigAction.class.php

示例2: query

 function query($ip)
 {
     if (!$ip) {
         return false;
     }
     $this->ip = $ip;
     list($a, $b, $c, $d) = explode('.', $ip);
     $query = $this->access_key . ".{$d}.{$c}.{$b}.{$a}." . $this->domain;
     $host = gethostbyname($query);
     list($first, $days, $score, $type) = explode('.', $host);
     if ($first == 127) {
         //spammer
         $this->days = $days;
         $this->score = $score;
         $this->type_num = $type;
         $this->type_txt = $this->answer_codes[$type];
         // search engine
         if ($type == 0) {
             $this->days = 0;
             $this->score = 0;
             $this->engine_num = $score;
             //$this->engine_txt	=$this->engine_codes[$score];
             return 1;
         } else {
             return 2;
         }
     }
     return 0;
 }
开发者ID:johngrange,项目名称:wookeyholeweb,代码行数:29,代码来源:honeypot.php

示例3: getLocation

 function getLocation($domainName)
 {
     $ipAddress = gethostbyname($domainName);
     $response = null;
     if ($ipAddress != $domainName) {
         $details_url = "http://ipinfo.io/" . gethostbyname($domainName);
         $response = json_decode(file_get_contents($details_url), true);
         //echo "ipinfo ";
         //var_dump($response);
     } else {
         //echo "domain does not exist";
     }
     if (!$response) {
         return array('lng' => null, 'lat' => null, 'address' => null);
     }
     $loc = explode(",", $response['loc']);
     $address = "";
     if ($response['org']) {
         $org = explode(" ", $response['org']);
         $org[0] = '';
         $org = implode(" ", $org);
         trim($org);
         $address = $org . ", ";
         if ($org) {
             $geo = $this->queryGeocode($org);
             if ($geo) {
                 return $geo;
             }
         }
     }
     $address .= isset($response['city']) ? $response['city'] . ", " : "";
     $address .= isset($response['region']) ? $response['region'] . ", " : "";
     $address .= isset($response['country']) ? $response['country'] : "";
     return ['lat' => $loc[0], 'lng' => $loc[1], 'address' => $address];
 }
开发者ID:ufrgs-hyman,项目名称:proxy-agg,代码行数:35,代码来源:NSIProxy.php

示例4: authorizeTestApiAccess

 public static function authorizeTestApiAccess()
 {
     if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'] && $_SERVER['REMOTE_ADDR'] != gethostbyname($_SERVER['HTTP_HOST'])) {
         JSON::error('Access to test API denied', 403);
         exit;
     }
 }
开发者ID:jmealo,项目名称:Gatekeeper,代码行数:7,代码来源:Gatekeeper.php

示例5: index

 public function index()
 {
     if (isset($_POST['config']) && isset($_POST['command_test'])) {
         $RESPONSE_END_TAG = "<END/>";
         $addr = gethostbyname("localhost");
         $client = stream_socket_client("tcp://{$addr}:2014", $errno, $errorMessage);
         if ($client === false) {
             throw new UnexpectedValueException("Failed to connect: {$errorMessage}");
         }
         $config = $_POST['config'];
         fwrite($client, 'test ' . $_POST['command_test'] . ' ' . $config);
         $server_response = stream_get_line($client, 1024, $RESPONSE_END_TAG);
         fclose($client);
         $response_code = substr($server_response, 0, 2);
         $server_response = substr($server_response, 3, strlen($server_response));
         $msg = '';
         $time = '';
         if ($response_code == 'OK') {
             $data = explode(') ', $server_response);
             $msg = str_replace('(', '', $data[0]) . '.';
             $time = str_replace(')', '', str_replace('(', '', $data[1])) . '.';
         } else {
             $msg = 'The following error occurred : ' . str_replace(')', '', str_replace('(', '', $server_response)) . '.';
         }
         header('Content-Type: application/json');
         echo json_encode(array('response' => nl2br($msg), 'others' => $time));
         //echo $msg."</br>".$time;
     } else {
         header('Content-Type: application/json');
         echo json_encode(array('response' => 'Missing parameters : Please fill all the required parameters ! ', 'others' => ''));
     }
 }
开发者ID:AnesBendimerad,项目名称:PDC---3---Bloom-Filter,代码行数:32,代码来源:testcontroller.php

示例6: open

 public function open($host, $port, $transport = 'tcp')
 {
     // if a socket is current open then close it
     $this->close();
     if (($ip = filter_var($host, FILTER_VALIDATE_IP)) !== false) {
         $this->host = $ip;
     } elseif (($ip = gethostbyname($host)) != $host) {
         $this->host = $ip;
     } else {
         throw new Exception('Unable to resolve host: ' . $host);
     }
     $this->port = filter_var($port, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 65535)));
     if (!$this->port) {
         throw new Exception('Invalid Port: ' . $port);
     }
     $err = 0;
     $msg = '';
     $this->stream = fsockopen("{$transport}://{$this->host}", $this->port, $err, $msg, $this->timeout);
     if (!$this->isOpen()) {
         throw new Exception("Unable to open socket: {$msg}", $err);
     }
     stream_set_timeout($this->stream, $this->timeout);
     stream_set_blocking($this->stream, $this->block);
     return $this;
 }
开发者ID:simon-downes,项目名称:spf,代码行数:25,代码来源:Socket.php

示例7: discover_new_device

function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
    global $config;
    if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) {
        $dst_host = $hostname . '.' . $config['mydomain'];
    } else {
        $dst_host = $hostname;
    }
    d_echo("discovering {$dst_host}\n");
    $ip = gethostbyname($dst_host);
    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
        // $ip isn't a valid IP so it must be a name.
        if ($ip == $dst_host) {
            d_echo("name lookup of {$dst_host} failed\n");
            log_event("{$method} discovery of " . $dst_host . " failed - Check name lookup", $device['device_id'], 'discovery');
            return false;
        }
    } elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true) {
        // gethostbyname returned a valid $ip, was $dst_host an IP?
        if ($config['discovery_by_ip'] === false) {
            d_echo('Discovery by IP disabled, skipping ' . $dst_host);
            log_event("{$method} discovery of " . $dst_host . " failed - Discovery by IP disabled", $device['device_id'], 'discovery');
            return false;
        }
    }
    d_echo("ip lookup result: {$ip}\n");
    $dst_host = rtrim($dst_host, '.');
    // remove trailing dot
    if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
        d_echo("{$ip} in an excluded network - skipping\n");
        return false;
    }
    if (match_network($config['nets'], $ip)) {
        try {
            $remote_device_id = addHost($dst_host, '', '161', 'udp', $config['distributed_poller_group']);
            $remote_device = device_by_id_cache($remote_device_id, 1);
            echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]';
            discover_device($remote_device);
            device_by_id_cache($remote_device_id, 1);
            if ($remote_device_id && is_array($device) && !empty($method)) {
                $extra_log = '';
                $int = ifNameDescr($interface);
                if (is_array($int)) {
                    $extra_log = ' (port ' . $int['label'] . ') ';
                }
                log_event('Device ' . $remote_device['hostname'] . " ({$ip}) {$extra_log} autodiscovered through {$method} on " . $device['hostname'], $remote_device_id, 'discovery');
            } else {
                log_event("{$method} discovery of " . $remote_device['hostname'] . " ({$ip}) failed - Check ping and SNMP access", $device['device_id'], 'discovery');
            }
            return $remote_device_id;
        } catch (HostExistsException $e) {
            // already have this device
        } catch (Exception $e) {
            log_event("{$method} discovery of " . $dst_host . " ({$ip}) failed - " . $e->getMessage());
        }
    } else {
        d_echo("{$ip} not in a matched network - skipping\n");
    }
    //end if
}
开发者ID:arrmo,项目名称:librenms,代码行数:60,代码来源:functions.inc.php

示例8: main

 public function main()
 {
     $count = array();
     $article = M('article');
     $type = M('type');
     $link = M('link');
     $hd = M('flash');
     $ping = M('pl');
     $guest = M('guestbook');
     $count['article'] = $article->count();
     //文章总数
     $count['narticle'] = $article->where('status=0')->count();
     //未审核文章总数
     $count['guestbook'] = $guest->count();
     //留言总数
     $count['nguestbook'] = $guest->where('status=0')->count();
     //未审核留言总数
     $count['type'] = $type->count();
     //栏目总数
     $count['link'] = $link->count();
     //链接总数
     $count['hd'] = $hd->count();
     //幻灯总数
     $count['ping'] = $ping->count();
     //评论总数
     $count['nping'] = $ping->where('status=0')->count();
     //未审核评论
     $this->assign('count', $count);
     unset($article, $type, $link, $hd, $ping, $guest);
     $info = array('操作系统' => PHP_OS, '运行环境' => $_SERVER["SERVER_SOFTWARE"], 'PHP运行方式' => php_sapi_name(), '上传附件限制' => ini_get('upload_max_filesize'), '执行时间限制' => ini_get('max_execution_time') . '秒', '服务器时间' => date("Y年n月j日 H:i:s"), '北京时间' => gmdate("Y年n月j日 H:i:s", time() + 8 * 3600), '服务器域名/IP' => $_SERVER['SERVER_NAME'] . ' [ ' . gethostbyname($_SERVER['SERVER_NAME']) . ' ]', '剩余空间' => round(@disk_free_space(".") / (1024 * 1024), 2) . 'M', 'register_globals' => get_cfg_var("register_globals") == "1" ? "ON" : "OFF", 'magic_quotes_gpc' => 1 === get_magic_quotes_gpc() ? 'YES' : 'NO', 'magic_quotes_runtime' => 1 === get_magic_quotes_runtime() ? 'YES' : 'NO');
     $this->assign('info', $info);
     $this->display('main');
 }
开发者ID:dalinhuang,项目名称:concourse,代码行数:33,代码来源:IndexAction.class.php

示例9: isSpam

 public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
 {
     if (!$ip || long2ip(ip2long($ip)) != $ip) {
         return;
     }
     $urls = $this->getLinks($content);
     array_unshift($urls, $site);
     foreach ($urls as $u) {
         $b = parse_url($u);
         if (!isset($b['host']) || !$b['host']) {
             continue;
         }
         $domain = preg_replace('/^[\\w]{2,6}:\\/\\/([\\w\\d\\.\\-]+).*$/', '$1', $b['host']);
         $domain_elem = explode(".", $domain);
         $i = count($domain_elem) - 1;
         if ($i == 0) {
             // "domain" is 1 word long, don't check it
             return null;
         }
         $host = $domain_elem[$i];
         do {
             $host = $domain_elem[$i - 1] . '.' . $host;
             $i--;
             if (substr(gethostbyname($host . '.' . $this->server), 0, 3) == "127") {
                 $status = substr($domain, 0, 128);
                 return true;
             }
         } while ($i > 0);
     }
 }
开发者ID:nikrou,项目名称:dotclear,代码行数:30,代码来源:class.dc.filter.linkslookup.php

示例10: __construct

 function __construct()
 {
     $this->S['YourIP'] = @$_SERVER['REMOTE_ADDR'];
     $domain = $this->OS() ? $_SERVER['SERVER_ADDR'] : @gethostbyname($_SERVER['SERVER_NAME']);
     $this->S['DomainIP'] = @get_current_user() . ' - ' . $_SERVER['SERVER_NAME'] . '(' . $domain . ')';
     $this->S['Flag'] = empty($this->sysInfo['win_n']) ? @php_uname() : $this->sysInfo['win_n'];
     $os = explode(" ", php_uname());
     $oskernel = $this->OS() ? $os[2] : $os[1];
     $this->S['OS'] = $os[0] . '内核版本:' . $oskernel;
     $this->S['Language'] = getenv("HTTP_ACCEPT_LANGUAGE");
     $this->S['Name'] = $this->OS() ? $os[1] : $os[2];
     $this->S['Email'] = $_SERVER['SERVER_ADMIN'];
     $this->S['WebEngine'] = $_SERVER['SERVER_SOFTWARE'];
     $this->S['WebPort'] = $_SERVER['SERVER_PORT'];
     $this->S['WebPath'] = $_SERVER['DOCUMENT_ROOT'] ? str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) : str_replace('\\', '/', dirname(__FILE__));
     $this->S['ProbePath'] = str_replace('\\', '/', __FILE__) ? str_replace('\\', '/', __FILE__) : $_SERVER['SCRIPT_FILENAME'];
     $this->S['sTime'] = date('Y-m-d H:i:s');
     $this->sysInfo = $this->GetsysInfo();
     //var_dump($this->sysInfo);
     $CPU1 = $this->GetCPUUse();
     sleep(1);
     $CPU2 = $this->GetCPUUse();
     $data = $this->GetCPUPercent($CPU1, $CPU2);
     $this->CPU_Use = $data['cpu0']['user'] . "%us,  " . $data['cpu0']['sys'] . "%sy,  " . $data['cpu0']['nice'] . "%ni, " . $data['cpu0']['idle'] . "%id,  " . $data['cpu0']['iowait'] . "%wa,  " . $data['cpu0']['irq'] . "%irq,  " . $data['cpu0']['softirq'] . "%softirq";
     if (!$this->OS()) {
         $this->CPU_Use = '目前只支持Linux系统';
     }
     $this->hd = $this->GetDisk();
     $this->NetWork = $this->GetNetWork();
 }
开发者ID:sunxfancy,项目名称:Questionnaire,代码行数:30,代码来源:check.php

示例11: connect

 /**
  * Connect to the specified port. If called when the socket is
  * already connected, it disconnects and connects again.
  *
  * @param $addr string IP address or host name
  * @param $port int TCP port number
  * @param $persistent bool (optional) whether the connection is
  *        persistent (kept open between requests by the web server)
  * @param $timeout int (optional) how long to wait for data
  * @access public
  * @return mixed true on success or error object
  */
 function connect($addr, $port, $persistent = null, $timeout = null)
 {
     if (is_resource($this->fp)) {
         @fclose($this->fp);
         $this->fp = null;
     }
     if (strspn($addr, '.0123456789') == strlen($addr)) {
         $this->addr = $addr;
     } else {
         $this->addr = gethostbyname($addr);
     }
     $this->port = $port % 65536;
     if ($persistent !== null) {
         $this->persistent = $persistent;
     }
     if ($timeout !== null) {
         $this->timeout = $timeout;
     }
     $openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
     $errno = 0;
     $errstr = '';
     if ($this->timeout) {
         $fp = $openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
     } else {
         $fp = $openfunc($this->addr, $this->port, $errno, $errstr);
     }
     if (!$fp) {
         return $this->raiseError($errstr, $errno);
     }
     $this->fp = $fp;
     return $this->setBlocking($this->blocking);
 }
开发者ID:mickdane,项目名称:zidisha,代码行数:44,代码来源:Socket.php

示例12: main

 public function main()
 {
     //$upyun_img = $this->createImgUpYun();
     $info = array('操作系统' => PHP_OS, '运行环境' => $_SERVER["SERVER_SOFTWARE"], 'PHP运行方式' => php_sapi_name(), '上传附件限制' => ini_get('upload_max_filesize'), '执行时间限制' => ini_get('max_execution_time') . '秒', '服务器时间' => date("Y年n月j日 H:i:s"), '北京时间' => gmdate("Y年n月j日 H:i:s", time() + 8 * 3600), '服务器域名/IP' => $_SERVER['SERVER_NAME'] . ' [ ' . gethostbyname($_SERVER['SERVER_NAME']) . ' ]', '服务器剩余空间' => round(disk_free_space(".") / (1024 * 1024), 2) . 'M', 'register_globals' => get_cfg_var("register_globals") == "1" ? "ON" : "OFF", 'magic_quotes_gpc' => 1 === get_magic_quotes_gpc() ? 'YES' : 'NO', 'magic_quotes_runtime' => 1 === get_magic_quotes_runtime() ? 'YES' : 'NO');
     $this->assign('info', $info);
     $this->display();
 }
开发者ID:gzwyufei,项目名称:hp,代码行数:7,代码来源:PublicController.class.php

示例13: checktor

 public function checktor($addr)
 {
     // Creates empty array.
     $flags = array();
     // Sets tor variable to no.
     $flags['tor'] = "no";
     // Breaks the IP string up into an array.
     $p = explode(".", $addr);
     // Checks whether the user uses the IPv6 addy.
     // Returns the flags array with the false variable.
     if (strpos($addr, ':') != -1) {
         return $flags;
     }
     // Generates a new host name by means of the IP array and TOR string.
     $ahbladdr = $p['3'] . "." . $p['2'] . "." . $p['1'] . "." . $p['0'] . "." . "tor.ahbl.org";
     // Get the IP address corresponding to a given host name.
     $ahbl = gethostbyname($ahbladdr);
     // In the returned IP adress is one of the following, it is from the TOR network.
     // There is then a yes flag assigned to the flag array.
     if ($ahbl == "127.0.0.2") {
         $flags['transit'] = "yes";
         $flags['tor'] = "yes";
     }
     if ($ahbl == "127.0.0.3") {
         $flags['exit'] = "yes";
         $flags['tor'] = "yes";
     }
     // The flags array are returned to the isTor method.
     return $flags;
 }
开发者ID:FastLizard4,项目名称:waca,代码行数:30,代码来源:request.php

示例14: oosGetSystemInformation

 /**
  * Retreive server information
  *
  * @return array
  */
  function oosGetSystemInformation() {

    // Get database information
    $dbconn =& oosDBGetConn();
    $oostable =& oosDBGetTables();

    $db_host = $dbconn->host;
    $db_database = $dbconn->database;
    $phpv = phpversion();


    $db_result = $dbconn->ServerInfo($oostable['countries']);

    list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);

    return array('date' => oos_datetime_short(date('Y-m-d H:i:s')),
                 'system' => $_ENV["OS"],
                 'kernel' => $kernel,
                 'host' => $host,
                 'ip' => gethostbyname($host),
                 'uptime' => @exec('uptime'),
                 'HTTP_SERVER' => $_SERVER['SERVER_SOFTWARE'],
                 'php' => $phpv,
                 'zend' => (function_exists('zend_version') ? zend_version() : ''),
                 'db_server' => $db_host,
                 'db_ip' => gethostbyname(OOS_DB_SERVER),
                 'db_version' => OOS_DB_TYPE . $db_result['description'],
                 'db_database' => $db_database);
  }
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:34,代码来源:server_info.php

示例15: access_details

 function access_details()
 {
     $access_details = array();
     $access_details['domain'] = '';
     $access_details['ip'] = '';
     $access_details['directory'] = '';
     $access_details['server_hostname'] = '';
     $access_details['server_ip'] = '';
     if (function_exists('phpinfo')) {
         ob_start();
         phpinfo();
         $phpinfo = ob_get_contents();
         ob_end_clean();
         $list = strip_tags($phpinfo);
         $access_details['domain'] = $this->scrape_phpinfo($list, 'HTTP_HOST');
         $access_details['ip'] = $this->scrape_phpinfo($list, 'SERVER_ADDR');
         $access_details['directory'] = $this->scrape_phpinfo($list, 'SCRIPT_FILENAME');
         $access_details['server_hostname'] = $this->scrape_phpinfo($list, 'System');
         $access_details['server_ip'] = @gethostbyname($access_details['server_hostname']);
     }
     $access_details['domain'] = $access_details['domain'] ? $access_details['domain'] : $_SERVER['HTTP_HOST'];
     $access_details['ip'] = $access_details['ip'] ? $access_details['ip'] : $this->server_addr();
     $access_details['directory'] = $access_details['directory'] ? $access_details['directory'] : $this->path_translated();
     $access_details['server_hostname'] = $access_details['server_hostname'] ? $access_details['server_hostname'] : @gethostbyaddr($access_details['ip']);
     $access_details['server_hostname'] = $access_details['server_hostname'] ? $access_details['server_hostname'] : 'Unknown';
     $access_details['server_ip'] = $access_details['server_ip'] ? $access_details['server_ip'] : @gethostbyaddr($access_details['ip']);
     $access_details['server_ip'] = $access_details['server_ip'] ? $access_details['server_ip'] : 'Unknown';
     foreach ($access_details as $key => $value) {
         $access_details[$key] = $access_details[$key] ? $access_details[$key] : 'Unknown';
     }
     if ($this->valid_for_product_tiers) {
         $access_details['valid_for_product_tiers'] = $this->valid_for_product_tiers;
     }
     return $access_details;
 }
开发者ID:empotix,项目名称:travelo,代码行数:35,代码来源:auth.php


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