本文整理汇总了PHP中Net_IPv6::getNetmask方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_IPv6::getNetmask方法的具体用法?PHP Net_IPv6::getNetmask怎么用?PHP Net_IPv6::getNetmask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_IPv6
的用法示例。
在下文中一共展示了Net_IPv6::getNetmask方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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
}
示例2: 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;
}
示例3: verifyCidr
/**
* verify ip address /mask 10.10.10.10./24 - CIDR
*
* if subnet == 0 we dont check if IP is subnet -> needed for ipCalc
*/
function verifyCidr($cidr, $issubnet = 1)
{
/* split it to network and subnet */
$temp = explode("/", $cidr);
$network = $temp[0];
$netmask = $temp[1];
//if one part is missing die
if (empty($network) || empty($netmask)) {
$errors[] = _("Invalid CIDR format!");
}
/* Identify address type */
$type = IdentifyAddress($network);
/* IPv4 verification */
if ($type == 'IPv4') {
require_once 'PEAR/Net/IPv4.php';
$Net_IPv4 = new Net_IPv4();
if ($net = $Net_IPv4->parseAddress($cidr)) {
//validate IP
if (!$Net_IPv4->validateIP($net->ip)) {
$errors[] = _("Invalid IP address!");
} elseif ($net->network != $net->ip && $issubnet == 1) {
$errors[] = _("IP address cannot be subnet! (Consider using") . " " . $net->network . ")";
} elseif (!$Net_IPv4->validateNetmask($net->netmask)) {
$errors[] = _('Invalid netmask') . ' ' . $net->netmask;
}
} else {
$errors[] = _('Invalid CIDR format!');
}
} else {
require_once 'PEAR/Net/IPv6.php';
$Net_IPv6 = new Net_IPv6();
//validate IPv6
if (!$Net_IPv6->checkIPv6($cidr)) {
$errors[] = _("Invalid IPv6 address!");
} else {
//validate subnet
$subnet = $Net_IPv6->getNetmask($cidr);
$subnet = $Net_IPv6->compress($subnet);
//get subnet part
$subnetParse = explode("/", $cidr);
$subnetMask = $subnetParse[1];
$subnetNet = $subnetParse[0];
if ($subnetNet != $subnet && $issubnet == 1) {
$errors[] = _("IP address cannot be subnet! (Consider using") . " " . $subnet . "/" . $subnetMask . ")";
}
}
}
/* return array of errors */
return $errors;
}
示例4: explode
$reqdfields = explode(" ", "range_from range_to");
$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
if ($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from'])) {
$input_errors[] = gettext("A valid prefix range must be specified.");
}
if ($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to'])) {
$input_errors[] = gettext("A valid prefix range must be specified.");
}
if ($_POST['prefixrange_from'] && $_POST['prefixrange_to'] && $_POST['prefixrange_length']) {
$netmask = Net_IPv6::getNetmask($_POST['prefixrange_from'], $_POST['prefixrange_length']);
$netmask = Net_IPv6::compress($netmask);
if ($netmask != Net_IPv6::compress(strtolower($_POST['prefixrange_from']))) {
$input_errors[] = sprintf(gettext("Prefix Delegation From address is not a valid IPv6 Netmask for %s"), $netmask . '/' . $_POST['prefixrange_length']);
}
$netmask = Net_IPv6::getNetmask($_POST['prefixrange_to'], $_POST['prefixrange_length']);
$netmask = Net_IPv6::compress($netmask);
if ($netmask != Net_IPv6::compress(strtolower($_POST['prefixrange_to']))) {
$input_errors[] = sprintf(gettext("Prefix Delegation To address is not a valid IPv6 Netmask for %s"), $netmask . '/' . $_POST['prefixrange_length']);
}
}
$range_from_to_ok = true;
if ($_POST['range_from']) {
if (!is_ipaddrv6($_POST['range_from'])) {
$input_errors[] = gettext("A valid range must be specified.");
$range_from_to_ok = false;
} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' && !Net_IPv6::isInNetmask($_POST['range_from'], '::', $ifcfgsn)) {
$input_errors[] = sprintf(gettext("The prefix (upper %s bits) must be zero. Use the form %s"), $ifcfgsn, $str_help_mask);
$range_from_to_ok = false;
}
}
示例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;
}
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;
}
}
示例6: array
// Process founded IPv6 addresses
$valid[$ip_version] = array();
$check_networks = array();
if (count($ip_data)) {
foreach ($ip_data as $ifIndex => $addresses) {
if (!isset($cache['port_index'][$device_id][$ifIndex])) {
continue;
}
// continue if ifIndex not found
$port_id = $cache['port_index'][$device_id][$ifIndex];
foreach ($addresses as $ipv6_address => $entry) {
$update_array = array();
$ipv6_prefixlen = $entry['ipAddressPrefix'];
$ipv6_origin = $entry['ipAddressOrigin'];
$full_address = $ipv6_address . '/' . $ipv6_prefixlen;
$ipv6_network = Net_IPv6::getNetmask($full_address) . '/' . $ipv6_prefixlen;
$ipv6_compressed = Net_IPv6::compress($ipv6_address);
$full_compressed = $ipv6_compressed . '/' . $ipv6_prefixlen;
// First check networks
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network));
if (empty($ipv6_network_id)) {
$ipv6_network_id = dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks');
echo 'N';
}
// Check IPs in DB
if (isset($old_table[$ifIndex][$ipv6_address])) {
foreach (array('ipv6_prefixlen', 'ipv6_origin', 'ipv6_network_id', 'port_id') as $param) {
if ($old_table[$ifIndex][$ipv6_address][$param] != ${$param}) {
$update_array[$param] = ${$param};
}
}
示例7: 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;
}
}