本文整理汇总了PHP中inet_ntop函数的典型用法代码示例。如果您正苦于以下问题:PHP inet_ntop函数的具体用法?PHP inet_ntop怎么用?PHP inet_ntop使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inet_ntop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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;
}
示例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];
}
示例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);
}
示例6: getValue
public function getValue()
{
if ($this->_value === null) {
$this->_value = inet_ntop($this->_binary);
}
return $this->_value;
}
示例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;
}
示例8: getIpAttribute
protected function getIpAttribute($value)
{
if (!is_null($value)) {
$value = inet_ntop(gmp_export(gmp_init($value)));
}
return $value;
}
示例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);
}
示例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()));
}
示例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();
}
示例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));
}
示例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);
}
示例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);
}
示例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;
}
}