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


PHP IP::isIPv6方法代码示例

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


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

示例1: __construct

 /**
  * Construct an IP address representation.
  * @param string $address The textual representation of an IP address or CIDR range.
  */
 public function __construct($address)
 {
     // analyze address format
     $this->is_valid = IP::isIPAddress($address);
     if (!$this->is_valid) {
         return;
     }
     $this->is_ipv4 = IP::isIPv4($address);
     $this->is_ipv6 = !$this->is_ipv4 && IP::isIPv6($address);
     // analyze address range
     $this->is_range = IP::isValidBlock($address);
     $this->encoded_range = IP::parseRange($address);
     $this->range = array(IP::prettifyIP(IP::formatHex($this->encoded_range[self::START])), IP::prettifyIP(IP::formatHex($this->encoded_range[self::END])));
 }
开发者ID:bacoda,项目名称:Wikimedia-contrib,代码行数:18,代码来源:IP.php

示例2: testisIPv6

 /**
  * @covers IP::isIPv6
  */
 public function testisIPv6()
 {
     $this->assertFalse(IP::isIPv6(':fc:100::'), 'IPv6 starting with lone ":"');
     $this->assertFalse(IP::isIPv6('fc:100:::'), 'IPv6 ending with a ":::"');
     $this->assertFalse(IP::isIPv6('fc:300'), 'IPv6 with only 2 words');
     $this->assertFalse(IP::isIPv6('fc:100:300'), 'IPv6 with only 3 words');
     $this->assertTrue(IP::isIPv6('fc:100::'));
     $this->assertTrue(IP::isIPv6('fc:100:a::'));
     $this->assertTrue(IP::isIPv6('fc:100:a:d::'));
     $this->assertTrue(IP::isIPv6('fc:100:a:d:1::'));
     $this->assertTrue(IP::isIPv6('fc:100:a:d:1:e::'));
     $this->assertTrue(IP::isIPv6('fc:100:a:d:1:e:ac::'));
     $this->assertFalse(IP::isIPv6('fc:100:a:d:1:e:ac:0::'), 'IPv6 with 8 words ending with "::"');
     $this->assertFalse(IP::isIPv6('fc:100:a:d:1:e:ac:0:1::'), 'IPv6 with 9 words ending with "::"');
     $this->assertFalse(IP::isIPv6(':::'));
     $this->assertFalse(IP::isIPv6('::0:'), 'IPv6 ending in a lone ":"');
     $this->assertTrue(IP::isIPv6('::'), 'IPv6 zero address');
     $this->assertTrue(IP::isIPv6('::0'));
     $this->assertTrue(IP::isIPv6('::fc'));
     $this->assertTrue(IP::isIPv6('::fc:100'));
     $this->assertTrue(IP::isIPv6('::fc:100:a'));
     $this->assertTrue(IP::isIPv6('::fc:100:a:d'));
     $this->assertTrue(IP::isIPv6('::fc:100:a:d:1'));
     $this->assertTrue(IP::isIPv6('::fc:100:a:d:1:e'));
     $this->assertTrue(IP::isIPv6('::fc:100:a:d:1:e:ac'));
     $this->assertFalse(IP::isIPv6('::fc:100:a:d:1:e:ac:0'), 'IPv6 with "::" and 8 words');
     $this->assertFalse(IP::isIPv6('::fc:100:a:d:1:e:ac:0:1'), 'IPv6 with 9 words');
     $this->assertFalse(IP::isIPv6(':fc::100'), 'IPv6 starting with lone ":"');
     $this->assertFalse(IP::isIPv6('fc::100:'), 'IPv6 ending with lone ":"');
     $this->assertFalse(IP::isIPv6('fc:::100'), 'IPv6 with ":::" in the middle');
     $this->assertTrue(IP::isIPv6('fc::100'), 'IPv6 with "::" and 2 words');
     $this->assertTrue(IP::isIPv6('fc::100:a'), 'IPv6 with "::" and 3 words');
     $this->assertTrue(IP::isIPv6('fc::100:a:d', 'IPv6 with "::" and 4 words'));
     $this->assertTrue(IP::isIPv6('fc::100:a:d:1'), 'IPv6 with "::" and 5 words');
     $this->assertTrue(IP::isIPv6('fc::100:a:d:1:e'), 'IPv6 with "::" and 6 words');
     $this->assertTrue(IP::isIPv6('fc::100:a:d:1:e:ac'), 'IPv6 with "::" and 7 words');
     $this->assertTrue(IP::isIPv6('2001::df'), 'IPv6 with "::" and 2 words');
     $this->assertTrue(IP::isIPv6('2001:5c0:1400:a::df'), 'IPv6 with "::" and 5 words');
     $this->assertTrue(IP::isIPv6('2001:5c0:1400:a::df:2'), 'IPv6 with "::" and 6 words');
     $this->assertFalse(IP::isIPv6('fc::100:a:d:1:e:ac:0'), 'IPv6 with "::" and 8 words');
     $this->assertFalse(IP::isIPv6('fc::100:a:d:1:e:ac:0:1'), 'IPv6 with 9 words');
     $this->assertTrue(IP::isIPv6('fc:100:a:d:1:e:ac:0'));
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:46,代码来源:IPTest.php

示例3: validateTargetField

 /**
  * HTMLForm field validation-callback for Target field.
  * @since 1.18
  * @param $value String
  * @param $alldata Array
  * @param $form HTMLForm
  * @return Message
  */
 public static function validateTargetField($value, $alldata, $form)
 {
     global $wgBlockCIDRLimit;
     list($target, $type) = self::getTargetAndType($value);
     if ($type == Block::TYPE_USER) {
         # TODO: why do we not have a User->exists() method?
         if (!$target->getId()) {
             return $form->msg('nosuchusershort', wfEscapeWikiText($target->getName()));
         }
         $status = self::checkUnblockSelf($target, $form->getUser());
         if ($status !== true) {
             return $form->msg('badaccess', $status);
         }
     } elseif ($type == Block::TYPE_RANGE) {
         list($ip, $range) = explode('/', $target, 2);
         if (IP::isIPv4($ip) && $wgBlockCIDRLimit['IPv4'] == 32 || IP::isIPv6($ip) && $wgBlockCIDRLimit['IPv6'] == 128) {
             # Range block effectively disabled
             return $form->msg('range_block_disabled');
         }
         if (IP::isIPv4($ip) && $range > 32 || IP::isIPv6($ip) && $range > 128) {
             # Dodgy range
             return $form->msg('ip_range_invalid');
         }
         if (IP::isIPv4($ip) && $range < $wgBlockCIDRLimit['IPv4']) {
             return $form->msg('ip_range_toolarge', $wgBlockCIDRLimit['IPv4']);
         }
         if (IP::isIPv6($ip) && $range < $wgBlockCIDRLimit['IPv6']) {
             return $form->msg('ip_range_toolarge', $wgBlockCIDRLimit['IPv6']);
         }
     } elseif ($type == Block::TYPE_IP) {
         # All is well
     } else {
         return $form->msg('badipaddress');
     }
     return true;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:44,代码来源:SpecialBlock.php

示例4: getIP

 /**
  * Get the host's IP address.
  * Does not support IPv6 at present due to the lack of a convenient interface in PHP.
  * @throws MWException
  * @return string
  */
 protected function getIP()
 {
     if ($this->ip === null) {
         if (IP::isIPv4($this->host)) {
             $this->ip = $this->host;
         } elseif (IP::isIPv6($this->host)) {
             throw new MWException('$wgSquidServers does not support IPv6');
         } else {
             wfSuppressWarnings();
             $this->ip = gethostbyname($this->host);
             if ($this->ip === $this->host) {
                 $this->ip = false;
             }
             wfRestoreWarnings();
         }
     }
     return $this->ip;
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:24,代码来源:SquidPurgeClient.php

示例5: incrMissesRecent

 /**
  * Roughly increments the cache misses in the last hour by unique visitors
  * @param WebRequest $request
  * @return void
  */
 public function incrMissesRecent(WebRequest $request)
 {
     if (mt_rand(0, self::MISS_FACTOR - 1) == 0) {
         $cache = ObjectCache::getLocalClusterInstance();
         # Get a large IP range that should include the user  even if that
         # person's IP address changes
         $ip = $request->getIP();
         if (!IP::isValid($ip)) {
             return;
         }
         $ip = IP::isIPv6($ip) ? IP::sanitizeRange("{$ip}/32") : IP::sanitizeRange("{$ip}/16");
         # Bail out if a request already came from this range...
         $key = wfMemcKey(get_class($this), 'attempt', $this->mType, $this->mKey, $ip);
         if ($cache->get($key)) {
             return;
             // possibly the same user
         }
         $cache->set($key, 1, self::MISS_TTL_SEC);
         # Increment the number of cache misses...
         $key = $this->cacheMissKey();
         if ($cache->get($key) === false) {
             $cache->set($key, 1, self::MISS_TTL_SEC);
         } else {
             $cache->incr($key);
         }
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:32,代码来源:FileCacheBase.php

示例6: doBlock

 /**
  * Backend block code.
  * $userID and $expiry will be filled accordingly
  * @return array(message key, arguments) on failure, empty array on success
  */
 function doBlock(&$userId = null, &$expiry = null)
 {
     global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit, $wgBlockCIDRLimit;
     $userId = 0;
     # Expand valid IPv6 addresses, usernames are left as is
     $this->BlockAddress = IP::sanitizeIP($this->BlockAddress);
     # isIPv4() and IPv6() are used for final validation
     $rxIP4 = '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}';
     $rxIP6 = '\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}:\\w{1,4}';
     $rxIP = "({$rxIP4}|{$rxIP6})";
     # Check for invalid specifications
     if (!preg_match("/^{$rxIP}\$/", $this->BlockAddress)) {
         $matches = array();
         if (preg_match("/^({$rxIP4})\\/(\\d{1,2})\$/", $this->BlockAddress, $matches)) {
             # IPv4
             if ($wgSysopRangeBans) {
                 if (!IP::isIPv4($this->BlockAddress) || $matches[2] > 32) {
                     return array('ip_range_invalid');
                 } elseif ($matches[2] < $wgBlockCIDRLimit['IPv4']) {
                     return array('ip_range_toolarge', $wgBlockCIDRLimit['IPv4']);
                 }
                 $this->BlockAddress = Block::normaliseRange($this->BlockAddress);
             } else {
                 # Range block illegal
                 return array('range_block_disabled');
             }
         } elseif (preg_match("/^({$rxIP6})\\/(\\d{1,3})\$/", $this->BlockAddress, $matches)) {
             # IPv6
             if ($wgSysopRangeBans) {
                 if (!IP::isIPv6($this->BlockAddress) || $matches[2] > 128) {
                     return array('ip_range_invalid');
                 } elseif ($matches[2] < $wgBlockCIDRLimit['IPv6']) {
                     return array('ip_range_toolarge', $wgBlockCIDRLimit['IPv6']);
                 }
                 $this->BlockAddress = Block::normaliseRange($this->BlockAddress);
             } else {
                 # Range block illegal
                 return array('range_block_disabled');
             }
         } else {
             # Username block
             if ($wgSysopUserBans) {
                 $user = User::newFromName($this->BlockAddress);
                 if (!is_null($user) && $user->getId()) {
                     # Use canonical name
                     $userId = $user->getId();
                     $this->BlockAddress = $user->getName();
                 } else {
                     return array('nosuchusershort', htmlspecialchars($user ? $user->getName() : $this->BlockAddress));
                 }
             } else {
                 return array('badipaddress');
             }
         }
     }
     if ($wgUser->isBlocked() && $wgUser->getId() !== $userId) {
         return array('cant-block-while-blocked');
     }
     $reasonstr = $this->BlockReasonList;
     if ($reasonstr != 'other' && $this->BlockReason != '') {
         // Entry from drop down menu + additional comment
         $reasonstr .= wfMsgForContent('colon-separator') . $this->BlockReason;
     } elseif ($reasonstr == 'other') {
         $reasonstr = $this->BlockReason;
     }
     $expirestr = $this->BlockExpiry;
     if ($expirestr == 'other') {
         $expirestr = $this->BlockOther;
     }
     if (strlen($expirestr) == 0 || strlen($expirestr) > 50) {
         return array('ipb_expiry_invalid');
     }
     if (false === ($expiry = Block::parseExpiryInput($expirestr))) {
         // Bad expiry.
         return array('ipb_expiry_invalid');
     }
     if ($this->BlockHideName) {
         // Recheck params here...
         if (!$userId || !$wgUser->isAllowed('hideuser')) {
             $this->BlockHideName = false;
             // IP users should not be hidden
         } elseif ($expiry !== 'infinity') {
             // Bad expiry.
             return array('ipb_expiry_temp');
         } elseif (User::edits($userId) > self::HIDEUSER_CONTRIBLIMIT) {
             // Typically, the user should have a handful of edits.
             // Disallow hiding users with many edits for performance.
             return array('ipb_hide_invalid');
         }
     }
     # Create block object
     # Note: for a user block, ipb_address is only for display purposes
     $block = new Block($this->BlockAddress, $userId, $wgUser->getId(), $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, $this->BlockEmail, isset($this->BlockAllowUsertalk) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit);
     # Should this be privately logged?
     $suppressLog = (bool) $this->BlockHideName;
//.........这里部分代码省略.........
开发者ID:rocLv,项目名称:conference,代码行数:101,代码来源:SpecialBlockip.php

示例7: isIP

 /**
  * Does the string match an anonymous IPv4 address?
  *
  * This function exists for username validation, in order to reject
  * usernames which are similar in form to IP addresses. Strings such
  * as 300.300.300.300 will return true because it looks like an IP
  * address, despite not being strictly valid.
  *
  * We match \d{1,3}\.\d{1,3}\.\d{1,3}\.xxx as an anonymous IP
  * address because the usemod software would "cloak" anonymous IP
  * addresses like this, if we allowed accounts like this to be created
  * new users could get the old edits of these anonymous users.
  *
  * @param $name String to match
  * @return Bool
  */
 public static function isIP($name)
 {
     return preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.(?:xxx|\\d{1,3})$/', $name) || IP::isIPv6($name);
 }
开发者ID:slackfaith,项目名称:deadbrain_site,代码行数:20,代码来源:User.php

示例8: dump

function dump()
{
    $ipaddr = gethostbyname("nosslsearch.google.com");
    $ip = new IP();
    $OK = true;
    if (!$ip->isIPv4($ipaddr)) {
        $OK = false;
    }
    if (!$OK) {
        if ($ip->isIPv6($ipaddr)) {
            $OK = true;
        }
    }
    if (!$OK) {
        echo "Failed nosslsearch.google.com `{$ipaddr}` not an IP address...!!!\n";
        return;
    }
    $array = GetWebsitesList();
    if (count($array) == 0) {
        echo "Failed!!! -> GetWebsitesList();\n";
        return;
    }
    while (list($table, $fff) = each($array)) {
        echo "{$fff}\t{$ipaddr}\n";
    }
}
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:26,代码来源:exec.nosslsearch.google.com.php

示例9: Checkipv6Virts

function Checkipv6Virts()
{
    $unix = new unix();
    $sock = new sockets();
    $EnableipV6 = $sock->GET_INFO("EnableipV6");
    $NetBuilder = new system_nic();
    if (!is_numeric($EnableipV6)) {
        $EnableipV6 = 0;
    }
    if ($EnableipV6 == 0) {
        return;
    }
    $q = new mysql();
    $sql = "SELECT nic FROM nics_virtuals WHERE ipv6=1";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    $eths = array();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $eths[$ligne["nic"]] = $ligne["nic"];
    }
    if (count($eths) == 0) {
        echo "Starting......: " . date("H:i:s") . " Building Ipv6 virtuals IP -> 0 interface...\n";
        return;
    }
    $echo = $unix->find_program("echo");
    $ipbin = $unix->find_program("ip");
    $ip = new IP();
    $sh = array();
    while (list($eth, $ligne) = each($eths)) {
        echo "Starting......: " . date("H:i:s") . " Building Ipv6 virtuals IP for `{$eth}` interface...\n";
        $sh[] = "{$echo} 0 > /proc/sys/net/ipv6/conf/{$eth}/disable_ipv6";
        $sh[] = "{$echo} 0 > /proc/sys/net/ipv6/conf/{$eth}/autoconf";
        $sh[] = "{$echo} 0 > /proc/sys/net/ipv6/conf/{$eth}/accept_ra";
        $sh[] = "{$echo} 0 > /proc/sys/net/ipv6/conf/{$eth}/accept_ra_defrtr";
        $sh[] = "{$echo} 0 > /proc/sys/net/ipv6/conf/{$eth}/accept_ra_pinfo";
        $sh[] = "{$echo} 0 > /proc/sys/net/ipv6/conf/{$eth}/accept_ra_rtr_pref";
        $sql = "SELECT * FROM nics_virtuals WHERE ipv6=1 AND nic='{$eth}' ORDER BY ID DESC";
        $results = $q->QUERY_SQL($sql, "artica_backup");
        while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
            $ipv6addr = $ligne["ipaddr"];
            $netmask = $ligne["netmask"];
            if (!is_numeric($netmask)) {
                $netmask = 0;
            }
            if ($netmask == 0) {
                continue;
            }
            if (!$ip->isIPv6($ipv6addr)) {
                continue;
            }
            echo "Starting......: " . date("H:i:s") . " Building Ipv6 virtuals IP for `{$eth}` [{$ipv6addr}/{$netmask}]...\n";
            $sh[] = "{$ipbin} addr add dev {$eth} {$ipv6addr}/{$netmask}";
        }
    }
    if (count($sh) == 0) {
        return;
    }
    while (list($num, $cmdline) = each($sh)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Starting......: " . date("H:i:s") . " Building Ipv6 virtuals {$cmdline}\n";
        }
        shell_exec($cmdline);
    }
}
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:63,代码来源:exec.virtuals-ip.php

示例10: pingLimiter

 /**
  * Primitive rate limits: enforce maximum actions per time period
  * to put a brake on flooding.
  *
  * The method generates both a generic profiling point and a per action one
  * (suffix being "-$action".
  *
  * @note When using a shared cache like memcached, IP-address
  * last-hit counters will be shared across wikis.
  *
  * @param string $action Action to enforce; 'edit' if unspecified
  * @param int $incrBy Positive amount to increment counter by [defaults to 1]
  * @return bool True if a rate limiter was tripped
  */
 public function pingLimiter($action = 'edit', $incrBy = 1)
 {
     // Call the 'PingLimiter' hook
     $result = false;
     if (!Hooks::run('PingLimiter', array(&$this, $action, &$result, $incrBy))) {
         return $result;
     }
     global $wgRateLimits;
     if (!isset($wgRateLimits[$action])) {
         return false;
     }
     // Some groups shouldn't trigger the ping limiter, ever
     if (!$this->isPingLimitable()) {
         return false;
     }
     global $wgMemc;
     $limits = $wgRateLimits[$action];
     $keys = array();
     $id = $this->getId();
     $userLimit = false;
     if (isset($limits['anon']) && $id == 0) {
         $keys[wfMemcKey('limiter', $action, 'anon')] = $limits['anon'];
     }
     if (isset($limits['user']) && $id != 0) {
         $userLimit = $limits['user'];
     }
     if ($this->isNewbie()) {
         if (isset($limits['newbie']) && $id != 0) {
             $keys[wfMemcKey('limiter', $action, 'user', $id)] = $limits['newbie'];
         }
         if (isset($limits['ip'])) {
             $ip = $this->getRequest()->getIP();
             $keys["mediawiki:limiter:{$action}:ip:{$ip}"] = $limits['ip'];
         }
         if (isset($limits['subnet'])) {
             $ip = $this->getRequest()->getIP();
             $matches = array();
             $subnet = false;
             if (IP::isIPv6($ip)) {
                 $parts = IP::parseRange("{$ip}/64");
                 $subnet = $parts[0];
             } elseif (preg_match('/^(\\d+\\.\\d+\\.\\d+)\\.\\d+$/', $ip, $matches)) {
                 // IPv4
                 $subnet = $matches[1];
             }
             if ($subnet !== false) {
                 $keys["mediawiki:limiter:{$action}:subnet:{$subnet}"] = $limits['subnet'];
             }
         }
     }
     // Check for group-specific permissions
     // If more than one group applies, use the group with the highest limit
     foreach ($this->getGroups() as $group) {
         if (isset($limits[$group])) {
             if ($userLimit === false || $limits[$group][0] / $limits[$group][1] > $userLimit[0] / $userLimit[1]) {
                 $userLimit = $limits[$group];
             }
         }
     }
     // Set the user limit key
     if ($userLimit !== false) {
         list($max, $period) = $userLimit;
         wfDebug(__METHOD__ . ": effective user limit: {$max} in {$period}s\n");
         $keys[wfMemcKey('limiter', $action, 'user', $id)] = $userLimit;
     }
     $triggered = false;
     foreach ($keys as $key => $limit) {
         list($max, $period) = $limit;
         $summary = "(limit {$max} in {$period}s)";
         $count = $wgMemc->get($key);
         // Already pinged?
         if ($count) {
             if ($count >= $max) {
                 wfDebugLog('ratelimit', "User '{$this->getName()}' " . "(IP {$this->getRequest()->getIP()}) tripped {$key} at {$count} {$summary}");
                 $triggered = true;
             } else {
                 wfDebug(__METHOD__ . ": ok. {$key} at {$count} {$summary}\n");
             }
         } else {
             wfDebug(__METHOD__ . ": adding record for {$key} {$summary}\n");
             if ($incrBy > 0) {
                 $wgMemc->add($key, 0, intval($period));
                 // first ping
             }
         }
         if ($incrBy > 0) {
//.........这里部分代码省略.........
开发者ID:jpena88,项目名称:mediawiki-dokku-deploy,代码行数:101,代码来源:User.php

示例11: GetGoogleWebsitesList

function GetGoogleWebsitesList($g)
{
    $sock = new sockets();
    $DisableGoogleSSL = $sock->GET_INFO("DisableGoogleSSL");
    if (!is_numeric($DisableGoogleSSL)) {
        $DisableGoogleSSL = 0;
    }
    if ($DisableGoogleSSL == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Goolge SSL is allowed\n";
        }
        return $g;
    }
    $q = new mysql_squid_builder();
    $arrayDN = $q->GetFamilySitestt(null, true);
    while (list($table, $fff) = each($arrayDN)) {
        if (preg_match("#\\.(gov|gouv|gor|org|net|web|ac)\\.#", "google.{$table}")) {
            continue;
        }
        $array[] = "www.google.{$table}";
        $array[] = "google.{$table}";
    }
    $ipaddr = gethostbyname("nosslsearch.google.com");
    $ip = new IP();
    $unix = new unix();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $OK = true;
    if (!$ip->isIPv4($ipaddr)) {
        $OK = false;
    }
    if (!$OK) {
        if ($ip->isIPv6($ipaddr)) {
            $OK = true;
        }
    }
    if (!$OK) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Unable to resolve nosslsearch.google.com\n";
        }
        return $g;
    }
    while (list($a, $googlesite) = each($array)) {
        $g[] = "--address=/{$googlesite}/{$ipaddr}";
        $g[] = "--cname={$googlesite},nosslsearch.google.com";
    }
    return $g;
}
开发者ID:articatech,项目名称:artica,代码行数:47,代码来源:exec.dnsmasq.php

示例12: normaliseRange

 /** 
  * Gets rid of uneeded numbers in quad-dotted/octet IP strings
  * For example, 127.111.113.151/24 -> 127.111.113.0/24
  */
 static function normaliseRange($range)
 {
     $parts = explode('/', $range);
     if (count($parts) == 2) {
         // IPv6
         if (IP::isIPv6($range) && $parts[1] >= 64 && $parts[1] <= 128) {
             $bits = $parts[1];
             $ipint = IP::toUnsigned6($parts[0]);
             # Native 32 bit functions WONT work here!!!
             # Convert to a padded binary number
             $network = wfBaseConvert($ipint, 10, 2, 128);
             # Truncate the last (128-$bits) bits and replace them with zeros
             $network = str_pad(substr($network, 0, $bits), 128, 0, STR_PAD_RIGHT);
             # Convert back to an integer
             $network = wfBaseConvert($network, 2, 10);
             # Reform octet address
             $newip = IP::toOctet($network);
             $range = "{$newip}/{$parts[1]}";
         } else {
             if (IP::isIPv4($range) && $parts[1] >= 16 && $parts[1] <= 32) {
                 $shift = 32 - $parts[1];
                 $ipint = IP::toUnsigned($parts[0]);
                 $ipint = $ipint >> $shift << $shift;
                 $newip = long2ip($ipint);
                 $range = "{$newip}/{$parts[1]}";
             }
         }
     }
     return $range;
 }
开发者ID:BackupTheBerlios,项目名称:shoutwiki-svn,代码行数:34,代码来源:Block.php

示例13: canonicalize

 /**
  * Convert some unusual representations of IPv4 addresses to their
  * canonical dotted quad representation.
  *
  * This currently only checks a few IPV4-to-IPv6 related cases.  More
  * unusual representations may be added later.
  *
  * @param $addr something that might be an IP address
  * @return valid dotted quad IPv4 address or null
  */
 public static function canonicalize($addr)
 {
     if (self::isValid($addr)) {
         return $addr;
     }
     // Annoying IPv6 representations like ::ffff:1.2.3.4
     if (strpos($addr, ':') !== false && strpos($addr, '.') !== false) {
         $addr = str_replace('.', ':', $addr);
         if (IP::isIPv6($addr)) {
             return $addr;
         }
     }
     // IPv6 loopback address
     $m = array();
     if (preg_match('/^0*' . RE_IPV6_GAP . '1$/', $addr, $m)) {
         return '127.0.0.1';
     }
     // IPv4-mapped and IPv4-compatible IPv6 addresses
     if (preg_match('/^' . RE_IPV6_V4_PREFIX . '(' . RE_IP_ADD . ')$/i', $addr, $m)) {
         return $m[1];
     }
     if (preg_match('/^' . RE_IPV6_V4_PREFIX . RE_IPV6_WORD . ':' . RE_IPV6_WORD . '$/i', $addr, $m)) {
         return long2ip((hexdec($m[1]) << 16) + hexdec($m[2]));
     }
     return null;
     // give up
 }
开发者ID:amjadtbssm,项目名称:website,代码行数:37,代码来源:IP.php

示例14: ipv6_add

function ipv6_add()
{
    $ip = new IP();
    if (!$ip->isIPv6($_POST["RemoteAddAddrv6"])) {
        echo "No an IPv6 address...\n";
        return;
    }
    $sock = new sockets();
    $datas = explode("\n", $sock->GET_INFO("PowerDNSListenAddrV6"));
    while (list($index, $ipmask) = each($datas)) {
        $array[$ipmask] = $ipmask;
    }
    $array[$_POST["RemoteAddAddrv6"]] = $_POST["RemoteAddAddrv6"];
    while (list($index, $ipmask) = each($array)) {
        $f[] = $ipmask;
    }
    $sock->SaveConfigFile(@implode("\n", $f), "PowerDNSListenAddrV6");
    $sock->getFrameWork("cmd.php?pdns-restart=yes");
}
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:19,代码来源:pdns.listen-ip.php

示例15: pingLimiter

	/**
	 * Primitive rate limits: enforce maximum actions per time period
	 * to put a brake on flooding.
	 *
	 * @note When using a shared cache like memcached, IP-address
	 * last-hit counters will be shared across wikis.
	 *
	 * @param string $action Action to enforce; 'edit' if unspecified
	 * @param integer $incrBy Positive amount to increment counter by [defaults to 1]
	 * @return bool True if a rate limiter was tripped
	 */
	public function pingLimiter( $action = 'edit', $incrBy = 1 ) {
		// Call the 'PingLimiter' hook
		$result = false;
		if ( !wfRunHooks( 'PingLimiter', array( &$this, $action, &$result, $incrBy ) ) ) {
			return $result;
		}

		global $wgRateLimits;
		if ( !isset( $wgRateLimits[$action] ) ) {
			return false;
		}

		// Some groups shouldn't trigger the ping limiter, ever
		if ( !$this->isPingLimitable() ) {
			return false;
		}

		global $wgMemc, $wgRateLimitLog;
		wfProfileIn( __METHOD__ );

		$limits = $wgRateLimits[$action];
		$keys = array();
		$id = $this->getId();
		$userLimit = false;

		if ( isset( $limits['anon'] ) && $id == 0 ) {
			$keys[wfMemcKey( 'limiter', $action, 'anon' )] = $limits['anon'];
		}

		if ( isset( $limits['user'] ) && $id != 0 ) {
			$userLimit = $limits['user'];
		}
		if ( $this->isNewbie() ) {
			if ( isset( $limits['newbie'] ) && $id != 0 ) {
				$keys[wfMemcKey( 'limiter', $action, 'user', $id )] = $limits['newbie'];
			}
			if ( isset( $limits['ip'] ) ) {
				$ip = $this->getRequest()->getIP();
				$keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip'];
			}
			if ( isset( $limits['subnet'] ) ) {
				$ip = $this->getRequest()->getIP();
				$matches = array();
				$subnet = false;
				if ( IP::isIPv6( $ip ) ) {
					$parts = IP::parseRange( "$ip/64" );
					$subnet = $parts[0];
				} elseif ( preg_match( '/^(\d+\.\d+\.\d+)\.\d+$/', $ip, $matches ) ) {
					// IPv4
					$subnet = $matches[1];
				}
				if ( $subnet !== false ) {
					$keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
				}
			}
		}
		// Check for group-specific permissions
		// If more than one group applies, use the group with the highest limit
		foreach ( $this->getGroups() as $group ) {
			if ( isset( $limits[$group] ) ) {
				if ( $userLimit === false || $limits[$group] > $userLimit ) {
					$userLimit = $limits[$group];
				}
			}
		}
		// Set the user limit key
		if ( $userLimit !== false ) {
			list( $max, $period ) = $userLimit;
			wfDebug( __METHOD__ . ": effective user limit: $max in {$period}s\n" );
			$keys[wfMemcKey( 'limiter', $action, 'user', $id )] = $userLimit;
		}

		$triggered = false;
		foreach ( $keys as $key => $limit ) {
			list( $max, $period ) = $limit;
			$summary = "(limit $max in {$period}s)";
			$count = $wgMemc->get( $key );
			// Already pinged?
			if ( $count ) {
				if ( $count >= $max ) {
					wfDebug( __METHOD__ . ": tripped! $key at $count $summary\n" );
					if ( $wgRateLimitLog ) {
						wfSuppressWarnings();
						file_put_contents( $wgRateLimitLog, wfTimestamp( TS_MW ) . ' ' . wfWikiID() . ': ' . $this->getName() . " tripped $key at $count $summary\n", FILE_APPEND );
						wfRestoreWarnings();
					}
					$triggered = true;
				} else {
					wfDebug( __METHOD__ . ": ok. $key at $count $summary\n" );
//.........这里部分代码省略.........
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:101,代码来源:User.php


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