本文整理汇总了PHP中Net_IPv6::parseAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_IPv6::parseAddress方法的具体用法?PHP Net_IPv6::parseAddress怎么用?PHP Net_IPv6::parseAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_IPv6
的用法示例。
在下文中一共展示了Net_IPv6::parseAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFirstAvailableIPAddress
/**
* Get first available IP address
*/
function getFirstAvailableIPAddress($subnetId)
{
global $db;
# get variables from config file
$database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
/* get all ip addresses in subnet */
$query = 'SELECT `ip_addr` from `ipaddresses` where `subnetId` = "' . $subnetId . '" order by `ip_addr` ASC;';
/* execute */
try {
$ipAddresses = $database->getArray($query);
} catch (Exception $e) {
$error = $e->getMessage();
print "<div class='alert alert-error'>" . _('Error') . ":{$error}</div>";
return false;
}
/* get subnet */
$query = 'SELECT `subnet`,`mask` from `subnets` where `id` = "' . $subnetId . '";';
$subnet2 = $database->getArray($query);
$subnet = $subnet2[0]['subnet'];
$mask = $subnet2[0]['mask'];
/* create array of IP addresses */
$ipaddressArray[] = $subnet;
foreach ($ipAddresses as $ipaddress) {
$ipaddressArray[] = $ipaddress['ip_addr'];
}
//get array size
$size = sizeof($ipaddressArray);
$curr = 0;
//get type
$type = IdentifyAddress($subnet);
//if subnet is /32
if ($mask == "32" && $type == "IPv4") {
if ($size == 1) {
$firstAvailable = $ipaddressArray[0];
} else {
$firstAvailable = false;
}
} else {
if ($mask == "31" && $type == "IPv4") {
if ($size == 1) {
$firstAvailable = $ipaddressArray[0];
} else {
if ($size == 2) {
$delta = $ipaddressArray[1] - $ipaddressArray[0];
if ($delta == 1) {
$firstAvailable = $ipaddressArray[0];
} else {
$firstAvailable = gmp_strval(gmp_add($ipaddressArray[0], 1));
}
} else {
$firstAvailable = false;
}
}
} else {
if ($mask == "128" && $type == "IPv6") {
if ($size == 1) {
$firstAvailable = $ipaddressArray[0];
} else {
$firstAvailable = false;
}
} else {
if ($mask == "127" && $type == "IPv6") {
if ($size == 1) {
$firstAvailable = $ipaddressArray[0];
} else {
if ($size == 2) {
$delta = $ipaddressArray[1] - $ipaddressArray[0];
if ($delta == 1) {
$firstAvailable = $ipaddressArray[0];
} else {
$firstAvailable = gmp_strval(gmp_add($ipaddressArray[0], 1));
}
} else {
$firstAvailable = false;
}
}
} else {
if ($size == 1) {
$firstAvailable = gmp_strval(gmp_add($ipaddressArray[0], 1));
} else {
//get first change -> delta > 1
for ($m = 1; $m <= $size - 1; $m++) {
$delta = gmp_strval(gmp_sub($ipaddressArray[$m], $ipaddressArray[$m - 1]));
//compare with previous
if ($delta != 1) {
$firstAvailable = gmp_strval(gmp_add($ipaddressArray[$m - 1], 1));
$m = $size;
} else {
$firstAvailable = gmp_strval(gmp_add($ipaddressArray[$m], 1));
}
}
//if bcast ignore!
if ($type == "IPv4") {
require_once 'PEAR/Net/IPv4.php';
$Net_IPv4 = new Net_IPv4();
$net = $Net_IPv4->parseAddress(transform2long($subnet) . "/" . $mask);
if ($net->broadcast == transform2long($firstAvailable)) {
//.........这里部分代码省略.........