• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP inet_ntop函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: fromHexToIp

 public static function fromHexToIp($ip)
 {
     $hex = pack('H*', $ip);
     if (str_repeat('0', 24) === substr($hex, 0, 24)) {
         $hex = substr($hex, 24);
     }
     return inet_ntop($hex);
 }
开发者ID:gitter-badger,项目名称:IpFilterBundle,代码行数:8,代码来源:IpConverter.php


示例2: getClientIP

 /**
  * Returns the IP of the current client.
  * The IP address is validated against the security validator. In case of an invalid IP, IP_INVALID is returned.
  * @param bool Get the shorthand notation of an address.
  * @return string The ip address of the client.
  */
 public static final function getClientIP($shortHand = true)
 {
     //validate the handle to the server variable
     $handle = self::getServerHandle();
     $ip = self::IP_INVALID;
     switch (true) {
         case isset($handle['HTTP_CLIENT_IP']):
             //if there is a HTTP_CLIENT_IP variable, we parse this and use the first value in it.
             //this allows us to properly handle loadbalancers and cachers.
             $ar = explode(',', $handle['HTTP_CLIENT_IP']);
             $ip = trim(array_shift($ar));
             break;
         case isset($handle['HTTP_X_FORWARDED_FOR']):
             //if there is a HTTP_X_FORWARDED_FOR variable, we parse this and use the first value in it.
             //this allows us to properly handle loadbalancers and cachers.
             $ar = explode(',', $handle['HTTP_X_FORWARDED_FOR']);
             $ip = trim(array_shift($ar));
             break;
         case isset($handle['REMOTE_ADDR']):
             //if there is a REMOTE_ADDR variable, we parse this and use the first value in it.
             $ar = explode(',', $handle['REMOTE_ADDR']);
             $ip = trim(array_shift($ar));
             break;
     }
     $val = new \System\Security\Validate();
     if ($val->isIPAddress($ip, 'ip', true, true, false, false, true) == \System\Security\ValidateResult::VALIDATE_OK) {
         if ($shortHand) {
             return inet_ntop(inet_pton($ip));
         }
         return $ip;
     }
     return self::IP_INVALID;
 }
开发者ID:Superbeest,项目名称:Core,代码行数:39,代码来源:IP.class.php


示例3: ntop

 /**
  * Number to Protocol
  *
  * Converts an unpacked binary string into a printable IP address.
  *
  * @static
  * @access public
  * @param binary(string) $ip
  * @param boolean $shrink
  * @return string|false
  */
 public static function ntop($ip, $shrink = false)
 {
     // Dealing with IP protocol addresses is really tricky. Convert it to a binary sequence and it's really
     // easy! Run it through the pton() method and if it returns as a string it means the IP is valid and can be
     // converted to a protocol address using the built in PHP functionality. Otherwise return false.
     return is_string($ip = self::pton($ip, $shrink)) ? inet_ntop(pack('A' . strlen($ip), $ip)) : false;
 }
开发者ID:mynameiszanders,项目名称:yiiskeleton,代码行数:18,代码来源:IP.php


示例4: get_cache

function get_cache($host, $value)
{
    global $dev_cache;
    if (!isset($dev_cache[$host][$value])) {
        switch ($value) {
            case 'device_id':
                // Try by hostname
                $ip = inet_pton($host);
                if (inet_ntop($ip) === false) {
                    $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ?', array($host, $host));
                } else {
                    $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ? OR `ip` = ?', array($host, $host, $ip));
                }
                // If failed, try by IP
                if (!is_numeric($dev_cache[$host]['device_id'])) {
                    $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id', array($host));
                }
                break;
            case 'os':
                $dev_cache[$host]['os'] = dbFetchCell('SELECT `os` FROM devices WHERE `device_id` = ?', array(get_cache($host, 'device_id')));
                break;
            case 'version':
                $dev_cache[$host]['version'] = dbFetchCell('SELECT `version` FROM devices WHERE `device_id`= ?', array(get_cache($host, 'device_id')));
                break;
            default:
                return null;
        }
        //end switch
    }
    //end if
    return $dev_cache[$host][$value];
}
开发者ID:Tatermen,项目名称:librenms,代码行数:32,代码来源:syslog.php


示例5: nel_render_ban_panel_list

function nel_render_ban_panel_list($dataforce, $dbh)
{
    $render = new nel_render();
    nel_render_header($dataforce, $render, array());
    nel_render_ban_panel_top($dataforce, $render);
    $result = $dbh->query('SELECT * FROM ' . BANTABLE . ' ORDER BY id DESC');
    $bgclass = 'row1';
    while ($baninfo = $result->fetch(PDO::FETCH_ASSOC)) {
        $render->add_data('ban_panel_loop', TRUE);
        $render->add_data('host', @inet_ntop($render->retrieve_data('host')) ? inet_ntop($render->retrieve_data('host')) : 'Unknown');
        $render->add_data('ban_appeal_response', $baninfo['appeal_response']);
        $render->add_data('ban_expire', date("D F jS Y  H:i:s", $render->retrieve_data('length') + $render->retrieve_data('ban_time')));
        if ($bgclass === 'row1') {
            $render->add_data('bg_class', 'row2');
            $bgclass = 'row2';
        } else {
            $render->add_data('bg_class', 'row1');
            $bgclass = 'row1';
        }
        $render->parse('bans_panel_list_bans.tpl', 'management');
    }
    unset($result);
    nel_render_ban_panel_bottom($dataforce, $render);
    nel_render_basic_footer($render);
    $render->output(TRUE);
}
开发者ID:OtakuMegane,项目名称:Nelliel,代码行数:26,代码来源:ban-panel-generation.php


示例6: getValue

 public function getValue()
 {
     if ($this->_value === null) {
         $this->_value = inet_ntop($this->_binary);
     }
     return $this->_value;
 }
开发者ID:scriptbunny,项目名称:php-cassandra,代码行数:7,代码来源:Inet.php


示例7: getNode

 /**
  * Converts gRPC node object to NetAssist node
  * @param \ng_rpc\Node $rpc_node gRPC Node object
  * @return \NetAssist\Graph\Node Node
  */
 public function getNode($rpc_node)
 {
     $node = new \NetAssist\Graph\Node($rpc_node->getId($rpc_node->GetId()));
     $node->db_id = $rpc_node->getDbId();
     $node->name = $rpc_node->getName();
     $node->model = $rpc_node->getModel();
     $node->serial = $rpc_node->getSerial();
     $node->icinga_name = $rpc_node->getIcingaName();
     $node->ip = long2ip($rpc_node->getIp4());
     if ($rpc_node->hasIp6()) {
         $node->ip6 = inet_ntop($rpc_node->getIp6());
     }
     $node->mac_address = $rpc_node->getMacAddress();
     $node->comment = $rpc_node->getComment();
     $node->ports_number = $rpc_node->getNumPorts();
     $node->address = $rpc_node->getAddress();
     $node->type = $rpc_node->getType();
     $states = $rpc_node->getStatesList();
     foreach ($states as $state) {
         $node->status[] = $this->getNodeStatus($state);
     }
     $rpc_metrics = $rpc_node->getLastMetricValuesList();
     foreach ($rpc_metrics as $rpc_metric) {
         $metric = new \NetAssist\Graph\NodeMetric();
         $metric->name = $rpc_metric->getKey();
         $metric->values = array();
         $rpc_values = $rpc_metric->getValue()->getValuesList();
         foreach ($rpc_values as $rpc_value) {
             $metric->values[] = $this->getNodeMetricValue($rpc_value);
         }
         $node->metrics[] = $metric;
     }
     return $node;
 }
开发者ID:netassist-ua,项目名称:netgraphz2-gpl,代码行数:39,代码来源:RPCAdapter.php


示例8: getIpAttribute

 protected function getIpAttribute($value)
 {
     if (!is_null($value)) {
         $value = inet_ntop(gmp_export(gmp_init($value)));
     }
     return $value;
 }
开发者ID:danhunsaker,项目名称:eloquent-mutant-caster,代码行数:7,代码来源:CastIP.php


示例9: __construct

 public function __construct($cidr = null, $end = null)
 {
     if ($cidr === null || $cidr === "") {
         return parent::__construct(Request::ip());
     }
     // Passing a static, return it.
     if ($cidr instanceof static) {
         // If no end, return $cidr.
         if ($end === null) {
             return parent::__construct($cidr->getStart(), $cidr->getEnd());
         }
         // If end is a static, we are creating a range with two exising IPs.
         if ($end instanceof static) {
             $end = $end->getEnd();
         }
         // If $end is binary, return it to base64.
         if (is_binary($end)) {
             $end = inet_ntop($end);
         }
         return parent::__construct($cidr->getStart(), $end);
     } else {
         if (is_binary($cidr)) {
             try {
                 $start = inet_ntop($cidr);
             } catch (\Exception $e) {
                 Log::warning("App\\Support\\IP::__construct trying to make IP from \$cidr binary value \"{$cidr}\" 0x" . bin2hex($cidr) . ", but it's not a real IP!");
                 if (!env('APP_DEBUG', false)) {
                     $start = "127.0.0.1";
                 } else {
                     throw $e;
                 }
             }
         } else {
             try {
                 $start = inet_ntop($cidr);
             } catch (\Exception $e) {
                 $start = $cidr;
             }
         }
     }
     // Passing a static, return it.
     if ($end instanceof static) {
         return parent::__construct($start, $end->getEnd());
     } else {
         if (is_binary($end)) {
             try {
                 $end = inet_ntop($end);
             } catch (\Exception $e) {
                 Log::warning("App\\Support\\IP::__construct trying to make IP from \$end binary value \"{$cidr}\" 0x" . bin2hex($end) . ", but it's not a real IP!");
                 if (!env('APP_DEBUG', false)) {
                     $end = "127.0.0.1";
                 } else {
                     throw $e;
                 }
             }
         }
     }
     return parent::__construct($start, $end);
 }
开发者ID:GodOfConquest,项目名称:infinity-next,代码行数:59,代码来源:IP.php


示例10: render

 /**
  * Render the grid cell value
  *
  * @param Varien_Object $row
  * @return string
  */
 public function render(Varien_Object $row)
 {
     /**
      * The output of the "inet_ntop" function was disabled to prevent an error throwing
      * in case when the database value is not an ipv6 or an ipv4 binary representation (ex. NULL).
      */
     return @inet_ntop($row->getData($this->getColumn()->getIndex()));
 }
开发者ID:chucky515,项目名称:Magento-CE-Mirror,代码行数:14,代码来源:Ip.php


示例11: format

 /**
  * format
  *
  * This makes the Access object a nice fuzzy human readable object, spiffy
  * ain't it.
  */
 public function format()
 {
     $this->f_start = inet_ntop($this->start);
     $this->f_end = inet_ntop($this->end);
     $this->f_user = $this->get_user_name();
     $this->f_level = $this->get_level_name();
     $this->f_type = $this->get_type_name();
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:14,代码来源:access.class.php


示例12: getShortAddress

 /**
  * Get Short Address
  *
  * Converts an IP address into the smallest protocol notation it can; dot-notation
  * for IPv4, and compacted (double colons) notation for IPv6.
  *
  * @return string
  */
 public function getShortAddress()
 {
     // If the binary representation of the IP address begins with 12 zeros,
     // it means it's an IPv4 address. Remove the zero's first so that PHP's
     // in-built number-to-protocol function will convert it accordingly.
     $ip = preg_replace('/^\\0{12}/', '', $this->getBinary());
     return inet_ntop(pack('A' . $this->getIpLength($ip), $ip));
 }
开发者ID:darsyn,项目名称:ip,代码行数:16,代码来源:IP.php


示例13: extract

 /**
  * Helper function to transform the ip and format it correctly for extraction.
  * If inputted with a string, it will leave it the same.
  * If inputted with a binary string, it will output an unpacked human readable string.
  *
  * @return $ip string
  */
 public function extract($ip)
 {
     //human readable string
     if (ctype_print($ip)) {
         return $ip;
     }
     return inet_ntop($ip);
 }
开发者ID:polycademy,项目名称:polyauth,代码行数:15,代码来源:IpTransformer.php


示例14: inet_ntop

 /**
  * Return dot or colon notation of IPv4 or IPv6 address.
  *
  * @param string $ip
  * @return string|bool
  */
 public static function inet_ntop($ip)
 {
     // trim this to the IPv4 equiv if it's in the mapped range
     if (wfWAFUtils::strlen($ip) == 16 && wfWAFUtils::substr($ip, 0, 12) == "ÿÿ") {
         $ip = wfWAFUtils::substr($ip, 12, 4);
     }
     return self::hasIPv6Support() ? inet_ntop($ip) : self::_inet_ntop($ip);
 }
开发者ID:GafaMX,项目名称:operaciondespierta.org,代码行数:14,代码来源:utils.php


示例15: bin2str

 /**
  * Convert a binary-encoded address to string
  * 
  * @param	string	$bin_addr
  * @param	string	$always_v6
  * @return	string|boolean
  */
 public static function bin2str($bin_addr, $always_v6 = false)
 {
     $str_addr = inet_ntop($bin_addr);
     if (!$always_v6 && self::isSixToFour($str_addr)) {
         return self::convSixToFour($str_addr);
     } else {
         return $str_addr;
     }
 }
开发者ID:wrossmann,项目名称:sixtofour,代码行数:16,代码来源:SixToFour.php


示例16: value

 public function value($value)
 {
     $value = parent::value($value);
     if (is_null($value)) {
         return inet_pton($_SERVER['REMOTE_ADDR']);
     } else {
         return Validate::ip($value) ? inet_pton($value) : inet_ntop($value);
     }
 }
开发者ID:Burgestrand,项目名称:sprig,代码行数:9,代码来源:ip.php


示例17: normalizeHostip

 public static function normalizeHostip($hostip)
 {
     $normalized = false;
     if ($hostip === false || $hostip === "") {
         $normalized = $hostip;
     } elseif (($pton = @inet_pton($hostip)) !== false) {
         $normalized = strtolower(inet_ntop($pton));
     }
     return $normalized;
 }
开发者ID:TheBillPleaseZA,项目名称:phplogmon,代码行数:10,代码来源:QueryHostip.class.php


示例18: applyTransformation

 /**
  * Does the actual work of each specific transformations plugin.
  *
  * @param string $buffer  text to be transformed. a binary string containing
  *                        an IP address, as returned from MySQL's INET6_ATON
  *                        function
  * @param array  $options transformation options
  * @param string $meta    meta information
  *
  * @return string IP address
  */
 public function applyTransformation($buffer, $options = array(), $meta = '')
 {
     $length = strlen($buffer);
     if ($length == 4 || $length == 16) {
         $val = @inet_ntop(pack('A' . $length, $buffer));
         if ($val !== false) {
             return $val;
         }
     }
     return $buffer;
 }
开发者ID:hewenhao2008,项目名称:phpmyadmin,代码行数:22,代码来源:Text_Plain_Binarytoip.class.php


示例19: getIp

 /**
  * Returns the IPAddress string, null if no ip address has been set
  * @param int $format Uses the IPAddress::FORMAT_* constants
  * @throws \Exception Throws an exception if the value is not null and no valid format constant is given
  * @return string|null
  */
 public function getIp($format = self::FORMAT_HEX)
 {
     if ($this->ipHex === null) {
         return null;
     } elseif ($format === self::FORMAT_HEX) {
         return $this->ipHex;
     } elseif ($format === self::FORMAT_IP_STRING) {
         return inet_ntop($this->hex2bin($this->ipHex));
     }
     throw new \Exception('Invalid IP format');
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:17,代码来源:IPAddress.php


示例20: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $value = $recordToHandle->getValue($this->field);
     if (!$value) {
         $recordToHandle->setValue($this->field, 0);
         return;
     }
     $newValue = $this->isIpPacked ? ip2long(inet_ntop($value)) : ip2long($value);
     $recordToHandle->setValue($this->field, $newValue);
 }
开发者ID:Mohitsahu123,项目名称:data-migration-tool-ce,代码行数:14,代码来源:ConvertIp.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP inet_pton函数代码示例发布时间:2022-05-15
下一篇:
PHP inet6_ntop函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap