Esempio n. 1
0
/**
 * Calculate reverse DNS entry for IPv6 addresses
 * If a prefix length is given, generate only up to this length (ie. for zone definitions) 
 */
function calculateReverseDNS6($ipv6, $pflen = 128)
{
    $uncompressed = Net_IPv6::removeNetmaskSpec(Net_IPv6::uncompress($ipv6));
    $len = $pflen / 4;
    $parts = explode(':', $uncompressed);
    $res = '';
    foreach ($parts as $part) {
        $res .= str_pad($part, 4, '0', STR_PAD_LEFT);
    }
    $res = implode('.', str_split(strrev(substr($res, 0, $len)))) . '.ip6.arpa';
    if ($pflen % 4 != 0) {
        $res .= " " . _("(closest parent)");
    }
    return $res;
}
Esempio n. 2
0
 /**
 * Converts an IPv6 address from Hex into Binary representation.
 *
 * @param String $ip the IP to convert (a:b:c:d:e:f:g:h),
 *                   compressed IPs are allowed
 *
 * @return String the binary representation
 * @access private
 @ @since 1.1.0
 */
 protected static function _ip2Bin($ip)
 {
     $binstr = '';
     $ip = Net_IPv6::removeNetmaskSpec($ip);
     $ip = Net_IPv6::Uncompress($ip);
     $parts = explode(':', $ip);
     foreach ($parts as $v) {
         $str = base_convert($v, 16, 2);
         $binstr .= str_pad($str, 16, '0', STR_PAD_LEFT);
     }
     return $binstr;
 }
Esempio n. 3
0
/**
 * verify ip address from edit / add
 * noStrict ignores NW and Broadcast checks
 */
function VerifyIpAddress($ip, $subnet, $noStrict = false)
{
    /* First identify it */
    $type = IdentifyAddress($ip);
    $type = IdentifyAddress($subnet);
    /* get mask */
    $mask = explode("/", $subnet);
    /* IPv4 verification */
    if ($type == 'IPv4') {
        require_once 'PEAR/Net/IPv4.php';
        $Net_IPv4 = new Net_IPv4();
        // is it valid?
        if (!$Net_IPv4->validateIP($ip)) {
            $error = _("IP address not valid") . "! ({$ip})";
        } elseif (!$Net_IPv4->ipInNetwork($ip, $subnet)) {
            $error = _("IP address not in selected subnet") . "! ({$ip})";
        } elseif ($mask[1] == "31" || $mask[1] == "32" || $noStrict == true) {
        } else {
            $net = $Net_IPv4->parseAddress($subnet);
            if ($net->network == $ip) {
                $error = _("Cannot add subnet as IP address!");
            } elseif ($net->broadcast == $ip) {
                $error = _("Cannot add broadcast as IP address!");
            }
        }
    } else {
        require_once 'PEAR/Net/IPv6.php';
        $Net_IPv6 = new Net_IPv6();
        //remove /xx from subnet
        $subnet_short = $Net_IPv6->removeNetmaskSpec($subnet);
        // is it valid?
        if (!$Net_IPv6->checkIPv6($ip)) {
            $error = _("IP address not valid") . "! ({$ip})";
        } elseif (!$Net_IPv6->isInNetmask($ip, $subnet)) {
            $error = _("IP address not in selected subnet") . "! ({$ip})";
        }
    }
    /* return results */
    if (isset($error)) {
        return $error;
    } else {
        return false;
    }
}