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


PHP Net_IPv6::getAddressType方法代码示例

本文整理汇总了PHP中Net_IPv6::getAddressType方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_IPv6::getAddressType方法的具体用法?PHP Net_IPv6::getAddressType怎么用?PHP Net_IPv6::getAddressType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net_IPv6的用法示例。


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

示例1: calculateIpCalcResult

/**
 * ipCalc calculations
 */
function calculateIpCalcResult($cidr)
{
    /* first verify address type */
    $type = IdentifyAddress($cidr);
    /* IPv4 */
    if ($type == "IPv4") {
        $net = Net_IPv4::parseAddress($cidr);
        //set ip address type
        $out['Type'] = 'IPv4';
        //calculate network details
        $out['IP address'] = $net->ip;
        // 192.168.0.50
        $out['Network'] = $net->network;
        // 192.168.0.0
        $out['Broadcast'] = $net->broadcast;
        // 192.168.255.255
        $out['Subnet bitmask'] = $net->bitmask;
        // 16
        $out['Subnet netmask'] = $net->netmask;
        // 255.255.0.0
        $out['Subnet wildcard'] = long2ip(~ip2long($net->netmask));
        //0.0.255.255
        //calculate min/max IP address
        $out['Min host IP'] = long2ip(ip2long($out['Network']) + 1);
        $out['Max host IP'] = long2ip(ip2long($out['Broadcast']) - 1);
        $out['Number of hosts'] = ip2long($out['Broadcast']) - ip2long($out['Min host IP']);
        //subnet class
        $out['Subnet Class'] = checkIpv4AddressType($out['Network'], $out['Broadcast']);
        //if IP == subnet clear the Host fields
        if ($out['IP address'] == $out['Network']) {
            $out['IP address'] = "/";
        }
    } else {
        //set ip address type
        $out['Type'] = 'IPv6';
        //calculate network details
        /*         $out['Host address']              = Net_IPv6::removeNetmaskSpec ( $cidr );  */
        $out['Host address'] = $cidr;
        $out['Host address'] = Net_IPv6::compress($out['Host address'], 1);
        $out['Host address (uncompressed)'] = Net_IPv6::uncompress($out['Host address']);
        $mask = Net_IPv6::getNetmaskSpec($cidr);
        $subnet = Net_IPv6::getNetmask($cidr);
        $out['Subnet prefix'] = Net_IPv6::compress($subnet) . '/' . $mask;
        $out['Prefix length'] = Net_IPv6::getNetmaskSpec($cidr);
        // get reverse DNS entries
        $out['Host Reverse DNS'] = calculateReverseDNS6($out['Host address (uncompressed)']);
        $out['Subnet Reverse DNS'] = calculateReverseDNS6($subnet, $mask);
        //if IP == subnet clear the Host fields and Host Reverse DNS
        if ($out['Host address'] == $out['Subnet prefix']) {
            $out['Host address'] = '/';
            $out['Host address (uncompressed)'] = '/';
            unset($out['Host Reverse DNS']);
        }
        //min / max hosts
        $maxIp = gmp_strval(gmp_add(gmp_sub(gmp_pow(2, 128 - $mask), 1), ip2long6($subnet)));
        $out['Min host IP'] = long2ip6(gmp_strval(gmp_add(ip2long6($subnet), 1)));
        $out['Max host IP'] = long2ip6($maxIp);
        $out['Number of hosts'] = MaxHosts($mask, 1);
        //address type
        $out['Address type'] = Net_IPv6::getAddressType($cidr);
        $out['Address type'] = checkIpv6AddressType($out['Address type']);
    }
    /* return results */
    return $out;
}
开发者ID:retexica,项目名称:phpipam,代码行数:68,代码来源:functions-tools.php

示例2: is_ipv6_valid

function is_ipv6_valid($ipv6_address, $ipv6_prefixlen = NULL)
{
    if (strpos($ipv6_address, '/') !== FALSE) {
        list($ipv6_address, $ipv6_prefixlen) = explode('/', $ipv6_address);
    }
    // False if prefix less or equal 0 and more 128
    if (is_numeric($ipv6_prefixlen) && ($ipv6_prefixlen < '0' || $ipv6_prefixlen > '128')) {
        return FALSE;
    }
    // False if invalid IPv6 syntax
    if (!Net_IPv6::checkIPv6($ipv6_address)) {
        return FALSE;
    }
    $ipv6_type = Net_IPv6::getAddressType($ipv6_address);
    // False if link-local
    if ($ipv6_type == NET_IPV6_LOCAL_LINK || $ipv6_type == NET_IPV6_UNSPECIFIED) {
        return FALSE;
    }
    return TRUE;
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:20,代码来源:functions.inc.php

示例3: discover_process_ipv6

function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin)
{
    global $device, $config;
    $ipv6_network = Net_IPv6::getNetmask("{$ipv6_address}/{$ipv6_prefixlen}") . '/' . $ipv6_prefixlen;
    $ipv6_compressed = Net_IPv6::compress($ipv6_address);
    if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK) {
        # ignore link-locals (coming from IPV6-MIB)
        return;
    }
    if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
        $port_id = dbFetchCell("SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?", array($device['device_id'], $ifIndex));
        if (dbFetchCell("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?", array($ipv6_network)) < '1') {
            dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks');
            echo "N";
        }
        // Below looks like a duplicate of the above FIXME
        if (dbFetchCell("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?", array($ipv6_network)) < '1') {
            dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks');
            echo "N";
        }
        $ipv6_network_id = dbFetchCell("SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?", array($ipv6_network));
        if (dbFetchCell("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?", array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
            dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id), 'ipv6_addresses');
            echo "+";
        } else {
            echo ".";
        }
        $full_address = "{$ipv6_address}/{$ipv6_prefixlen}";
        $valid_address = $full_address . "-" . $port_id;
        $valid['ipv6'][$valid_address] = 1;
    }
}
开发者ID:REAP720801,项目名称:librenms,代码行数:32,代码来源:functions.inc.php

示例4: discover_process_ipv6

function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name = '')
{
    global $device;
    $ipv6_network = Net_IPv6::getNetmask("{$ipv6_address}/{$ipv6_prefixlen}") . '/' . $ipv6_prefixlen;
    $ipv6_compressed = Net_IPv6::compress($ipv6_address);
    if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK) {
        // ignore link-locals (coming from IPV6-MIB)
        return;
    }
    if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
        $port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex));
        if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') {
            dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks');
            echo 'N';
        } else {
            //Update Context
            dbUpdate(array('context_name' => $device['context_name']), 'ipv6_network', '`ipv6_network` = ?', array($ipv6_network));
            echo 'n';
        }
        $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name));
        if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
            dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses');
            echo '+';
        } else {
            //Update Context
            dbUpdate(array('context_name' => $device['context_name']), 'ipv6_address', '`ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id));
            echo '.';
        }
        $full_address = "{$ipv6_address}/{$ipv6_prefixlen}";
        $valid_address = $full_address . '-' . $port_id;
        $valid['ipv6'][$valid_address] = 1;
    }
    //end if
}
开发者ID:arrmo,项目名称:librenms,代码行数:34,代码来源:functions.inc.php

示例5: discover_process_ipv6

function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin)
{
    global $device, $config;
    $ipv6_network = Net_IPv6::getNetmask("{$ipv6_address}/{$ipv6_prefixlen}") . '/' . $ipv6_prefixlen;
    $ipv6_compressed = Net_IPv6::compress($ipv6_address);
    if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK) {
        # ignore link-locals (coming from IPV6-MIB)
        return;
    }
    # FIXME dbFacile
    if (mysql_result(mysql_query("SELECT count(*) FROM `ports`\n        WHERE device_id = '" . $device['device_id'] . "' AND `ifIndex` = '{$ifIndex}'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
        $i_query = "SELECT port_id FROM `ports` WHERE device_id = '" . $device['device_id'] . "' AND `ifIndex` = '{$ifIndex}'";
        $port_id = mysql_result(mysql_query($i_query), 0);
        if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '{$ipv6_network}'"), 0) < '1') {
            mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('{$ipv6_network}')");
            echo "N";
        }
        if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '{$ipv6_network}'"), 0) < '1') {
            mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('{$ipv6_network}')");
            echo "N";
        }
        $ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '{$ipv6_network}'"), 0);
        if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '{$ipv6_address}' AND `ipv6_prefixlen` = '{$ipv6_prefixlen}' AND `port_id` = '{$port_id}'"), 0) == '0') {
            mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `port_id`)\n                                   VALUES ('{$ipv6_address}', '{$ipv6_compressed}', '{$ipv6_prefixlen}', '{$ipv6_origin}', '{$ipv6_network_id}', '{$port_id}')");
            echo "+";
        } else {
            echo ".";
        }
        $full_address = "{$ipv6_address}/{$ipv6_prefixlen}";
        $valid_address = $full_address . "-" . $port_id;
        $valid['ipv6'][$valid_address] = 1;
    }
}
开发者ID:RomanBogachev,项目名称:observium,代码行数:33,代码来源:functions.inc.php


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