function getIp() { if (isset($this->details['location_ip'])) { return Piwik_Common::long2ip($this->details['location_ip']); } return false; }
/** * @dataProvider getLong2IPTestData * @group Core * @group IP */ public function testLong2ip($N, $P) { $this->assertEquals($P, Piwik_IP::long2ip($N), bin2hex($N)); // this is our compatibility function $this->assertEquals($P, Piwik_Common::long2ip($N), bin2hex($N)); }
/** * Returns the hostname given the string IP in the format ip2long * php.net/ip2long * * @param string $ip * * @return string hostname */ private function getHost($ip) { return trim(strtolower(@gethostbyaddr(Piwik_Common::long2ip($ip)))); }
function test_long2ip() { // a valid network address is either 4 or 16 bytes; those lines are intentionally left blank ;) $tests = array(null => '0.0.0.0', "" => '0.0.0.0', "" => '127.0.0.1', "��" => '192.168.1.1', "����" => '192.168.1.2', "���" => '0.0.0.0', "��" => '0.0.0.0', "��" => '0.0.0.0', '-1062731520' => '0.0.0.0', '3232235776' => '0.0.0.0', '168430090' => '0.0.0.0', '9999' => '57.57.57.57', "9999" => '57.57.57.57', '999' => '0.0.0.0', "999" => '0.0.0.0'); foreach ($tests as $N => $P) { $this->assertEqual(Piwik_IP::long2ip($N), $P, bin2hex($N)); // this is our compatibility function $this->assertEqual(Piwik_Common::long2ip($N), $P, bin2hex($N)); } }
/** * Checks if the visitor ip is in the excluded list * * @param string $ip Long IP * @return bool */ protected function isVisitorIpExcluded($ip) { $websiteAttributes = Piwik_Common::getCacheWebsiteAttributes($this->idsite); if (!empty($websiteAttributes['excluded_ips'])) { foreach ($websiteAttributes['excluded_ips'] as $ipRange) { if ($ip >= $ipRange[0] && $ip <= $ipRange[1]) { printDebug('Visitor IP ' . Piwik_Common::long2ip($ip) . ' is excluded from being tracked'); return true; } } } return false; }