Пример #1
16
function get_geodata($ip)
{
    require _TRACK_LIB_PATH . "/maxmind/geoipregionvars.php";
    // названия регионов
    if (defined('_PHP5_GEOIP_ENABLED') && _PHP5_GEOIP_ENABLED || function_exists('geoip_record_by_name')) {
        $geoinfo = geoip_record_by_name($ip);
        $ispname = geoip_isp_by_name($ip);
        $cur_city = $geoinfo['city'];
        $cur_region = $geoinfo['region'];
        $cur_country = $geoinfo['country_code'];
    } else {
        require _TRACK_LIB_PATH . "/maxmind/geoip.inc.php";
        require _TRACK_LIB_PATH . "/maxmind/geoipcity.inc.php";
        $gi = geoip_open(_TRACK_STATIC_PATH . "/maxmind/MaxmindCity.dat", GEOIP_STANDARD);
        $record = geoip_record_by_addr($gi, $ip);
        $ispname = geoip_org_by_addr($gi, $ip);
        geoip_close($gi);
        $cur_city = $record->city;
        $cur_region = $record->region;
        $cur_country = $record->country_code;
        // Resolve GeoIP extension conflict
        if (function_exists('geoip_country_code_by_name') && $cur_country == '') {
            $cur_country = geoip_country_code_by_name($ip);
        }
    }
    return array('country' => $cur_country, 'region' => $cur_region, 'state' => $GEOIP_REGION_NAME[$cur_country][$cur_region], 'city' => $cur_city, 'isp' => $ispname);
}
Пример #2
0
 function get_geodata($ip)
 {
     require_once _TRACK_LIB_PATH . "/maxmind/geoip.inc.php";
     require_once _TRACK_LIB_PATH . "/maxmind/geoipcity.inc.php";
     require_once _TRACK_LIB_PATH . "/maxmind/geoipregionvars.php";
     $gi = geoip_open(_TRACK_STATIC_PATH . "/maxmind/MaxmindCity.dat", GEOIP_STANDARD);
     $record = geoip_record_by_addr($gi, $ip);
     $isp = geoip_org_by_addr($gi, $ip);
     geoip_close($gi);
     $cur_country = $record->country_code;
     // Resolve GeoIP extension conflict
     if (function_exists('geoip_country_code_by_name') && $cur_country == '') {
         $cur_country = geoip_country_code_by_name($ip);
     }
     return array('country' => $cur_country, 'state' => $GEOIP_REGION_NAME[$record->country_code][$record->region], 'city' => $record->city, 'region' => $record->region, 'isp' => $isp);
 }
Пример #3
0
 public function testNetspeedcell()
 {
     $gi = geoip_open("tests/data/GeoIPNetSpeedCell.dat", GEOIP_STANDARD);
     $this->assertEquals('Dialup', geoip_org_by_addr($gi, "2.125.160.1"));
 }
Пример #4
0
#!/usr/bin/php -q
<?php 
// This code demonstrates how to lookup the country and region by IP Address
// It is designed to work with GeoIP Organization or GeoIP ISP available from MaxMind
include "../src/geoip.inc";
$gi = geoip_open("/usr/local/share/GeoIP/GeoIPDomain.dat", GEOIP_STANDARD);
$domain = geoip_org_by_addr($gi, "80.24.24.24");
print "80.24.24.24 belongs to " . $domain . "\n";
geoip_close($gi);
Пример #5
0
 /**
  * Uses a GeoIP database to get a visitor's location based on their IP address.
  *
  * This function will return different results based on the data used. If a city
  * database is used, it may return the country code, region code, city name, area
  * code, latitude, longitude and postal code of the visitor.
  *
  * Alternatively, if used with a country database, only the country code will be
  * returned.
  *
  * @param array $info Must have an 'ip' field.
  * @return array
  */
 public function getLocation($info)
 {
     $ip = $this->getIpFromInfo($info);
     $result = array();
     $locationGeoIp = $this->getGeoIpInstance($key = 'loc');
     if ($locationGeoIp) {
         switch ($locationGeoIp->databaseType) {
             case GEOIP_CITY_EDITION_REV0:
                 // city database type
             // city database type
             case GEOIP_CITY_EDITION_REV1:
             case GEOIP_CITYCOMBINED_EDITION:
                 $location = geoip_record_by_addr($locationGeoIp, $ip);
                 if (!empty($location)) {
                     $result[self::COUNTRY_CODE_KEY] = $location->country_code;
                     $result[self::REGION_CODE_KEY] = $location->region;
                     $result[self::CITY_NAME_KEY] = utf8_encode($location->city);
                     $result[self::AREA_CODE_KEY] = $location->area_code;
                     $result[self::LATITUDE_KEY] = $location->latitude;
                     $result[self::LONGITUDE_KEY] = $location->longitude;
                     $result[self::POSTAL_CODE_KEY] = $location->postal_code;
                 }
                 break;
             case GEOIP_REGION_EDITION_REV0:
                 // region database type
             // region database type
             case GEOIP_REGION_EDITION_REV1:
                 $location = geoip_region_by_addr($locationGeoIp, $ip);
                 if (!empty($location)) {
                     $result[self::COUNTRY_CODE_KEY] = $location[0];
                     $result[self::REGION_CODE_KEY] = $location[1];
                 }
                 break;
             case GEOIP_COUNTRY_EDITION:
                 // country database type
                 $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip);
                 break;
             default:
                 // unknown database type, log warning and fallback to country edition
                 Log::warning("Found unrecognized database type: %s", $locationGeoIp->databaseType);
                 $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip);
                 break;
         }
     }
     // NOTE: ISP & ORG require commercial dbs to test. this code has been tested manually,
     // but not by integration tests.
     $ispGeoIp = $this->getGeoIpInstance($key = 'isp');
     if ($ispGeoIp) {
         $isp = geoip_org_by_addr($ispGeoIp, $ip);
         if (!empty($isp)) {
             $result[self::ISP_KEY] = utf8_encode($isp);
         }
     }
     $orgGeoIp = $this->getGeoIpInstance($key = 'org');
     if ($orgGeoIp) {
         $org = geoip_org_by_addr($orgGeoIp, $ip);
         if (!empty($org)) {
             $result[self::ORG_KEY] = utf8_encode($org);
         }
     }
     if (empty($result)) {
         return false;
     }
     $this->completeLocationResult($result);
     return $result;
 }
Пример #6
0
#!/usr/bin/php -q
<?php 
// This code demonstrates how to lookup the country and region by IP Address
// It is designed to work with GeoIP Organization or GeoIP ISP available from MaxMind
include "geoip.inc";
$giorg = geoip_open("/usr/local/share/GeoIP/GeoIPOrg.dat", GEOIP_STANDARD);
$org = geoip_org_by_addr($giorg, "80.24.24.24");
print "80.24.24.24 belongs to " . $org . "\n";
$giisp = geoip_open("/usr/local/share/GeoIP/GeoIPISP.dat", GEOIP_STANDARD);
$isp = geoip_org_by_addr($giisp, "80.24.24.24");
print "80.24.24.24 has isp " . $isp . "\n";
geoip_close($giorg);
geoip_close($giisp);
?>

function getIspData($ip)
{
    $giisp = geoip_open($_SERVER['DOCUMENT_ROOT'] . "/202-config/geo/GeoIPISP.dat", GEOIP_STANDARD);
    $isp = geoip_org_by_addr($giisp, $ip);
    if (!$isp) {
        $isp = "Unknown ISP/Carrier";
    }
    geoip_close($giisp);
    return $isp;
}
Пример #8
0
#!/usr/bin/php -q
<?php 
// This code demonstrates how to lookup the country and region by IP Address
// It is designed to work with GeoIP Organization or GeoIP ISP available from MaxMind
include "geoip.inc";
$giorg = geoip_open("/usr/local/share/GeoIP/GeoIPLocA.dat", GEOIP_STANDARD);
$org = geoip_org_by_addr($giorg, "80.24.24.24");
print "80.24.24.24 belongs to " . $org . "ZZ\n";
geoip_close($giorg);
?>

 public function testDomain()
 {
     $gi = geoip_open("tests/data/GeoIPDomain.dat", GEOIP_STANDARD);
     $this->assertEquals('shoesfin.NET', geoip_org_by_addr($gi, "67.43.156.0"));
 }
Пример #10
0
function get_country_city_isp($ip)
{
    global $maxmind_gi;
    global $maxmind_giisp;
    global $GEOIP_REGION_NAME;
    // Don't waste resources on wrong IPs
    if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
        return array('', '', '', '', '');
    }
    $record = geoip_record_by_addr($maxmind_gi, $ip);
    $isp = geoip_org_by_addr($maxmind_giisp, $ip);
    $country = is_object($record) ? $record->country_code : '';
    // Resolve GeoIP extension conflict
    if (function_exists('geoip_country_code_by_name') && $country == '') {
        $country = geoip_country_code_by_name($ip);
    }
    if (is_object($record)) {
        if (isset($GEOIP_REGION_NAME[$record->country_code]) && $record->region != '') {
            if (isset($GEOIP_REGION_NAME[$record->country_code][$record->region])) {
                $state = $GEOIP_REGION_NAME[$record->country_code][$record->region];
            } else {
                $state = '';
            }
        } else {
            $state = '';
        }
        $city = $record->city;
        $region = $record->region;
    } else {
        $state = '';
        $city = '';
        $region = '';
    }
    return array($country, $state, $city, $region, $isp);
}
<?php

include "geoip.inc";
include "geoipcity.inc";
include "geoipregionvars.php";
if (isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']) && eregi("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\$", $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) {
    $ip = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = getenv("REMOTE_ADDR");
}
$gic = geoip_open("GEOAPI-01.dat", GEOIP_STANDARD);
$gi = geoip_open("GEOAPI-02.dat", GEOIP_STANDARD);
$giisp = geoip_open("GEOAPI-03.dat", GEOIP_STANDARD);
$isp = geoip_org_by_addr($giisp, $ip);
$record = geoip_record_by_addr($gi, $ip);
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="description" content="Detect Your IP location with Maps, Fast detection Country , Region , City , Latitude , Longitude , Metro code , Area Code , GeoIP based " />
        <meta name="keywords" content="ip2location, ip geo location, ip to location , GeoIP , Google Maps , County , City , ISP , Organization , Panggi Libersa" />
		<title>IPLoc.co.cc | IP Geo Location Info | Country , Region , City , Latitude , Longitude , Metro code , Area Code </title>
<style>
<!--
BODY {
	font-family: Tahoma, Verdana, sans-serif;
	font-size: 11px;
	font-weight: normal;
	text-decoration: none;
Пример #12
0
 public function testOrg()
 {
     $gi = geoip_open("tests/data/GeoIPOrg.dat", GEOIP_STANDARD);
     $this->assertEquals('AT&T Worldnet Services', geoip_org_by_addr($gi, "12.87.118.0"));
 }
Пример #13
0
 /**
  * Uses a GeoIP database to get a visitor's location based on their IP address.
  *
  * This function will return different results based on the data used. If a city
  * database is used, it may return the country code, region code, city name, area
  * code, latitude, longitude and postal code of the visitor.
  *
  * Alternatively, if used with a country database, only the country code will be
  * returned.
  *
  * @param array $info Must have an 'ip' field.
  * @return array
  */
 public function getLocation($info)
 {
     $ip = $this->getIpFromInfo($info);
     $isIPv6 = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
     $result = array();
     $locationGeoIp = $this->getGeoIpInstance($key = 'loc');
     if ($locationGeoIp) {
         switch ($locationGeoIp->databaseType) {
             case GEOIP_CITY_EDITION_REV0:
                 // city database type
             // city database type
             case GEOIP_CITY_EDITION_REV1:
             case GEOIP_CITYCOMBINED_EDITION:
                 if ($isIPv6) {
                     $location = geoip_record_by_addr_v6($locationGeoIp, $ip);
                 } else {
                     $location = geoip_record_by_addr($locationGeoIp, $ip);
                 }
                 if (!empty($location)) {
                     $result[self::COUNTRY_CODE_KEY] = $location->country_code;
                     $result[self::REGION_CODE_KEY] = $location->region;
                     if ($location->region == "18" && $location->city == "Milan") {
                         $result[self::REGION_CODE_KEY] = "09";
                     }
                     $result[self::CITY_NAME_KEY] = utf8_encode($location->city);
                     $result[self::AREA_CODE_KEY] = $location->area_code;
                     $result[self::LATITUDE_KEY] = $location->latitude;
                     $result[self::LONGITUDE_KEY] = $location->longitude;
                     $result[self::POSTAL_CODE_KEY] = $location->postal_code;
                 }
                 break;
             case GEOIP_REGION_EDITION_REV0:
                 // region database type
             // region database type
             case GEOIP_REGION_EDITION_REV1:
                 if ($isIPv6) {
                     // NOTE: geoip_region_by_addr_v6 does not exist (yet?), so we
                     // return the country code and an empty region code
                     $location = array(geoip_country_code_by_addr_v6($locationGeoIp, $ip), '');
                 } else {
                     $location = geoip_region_by_addr($locationGeoIp, $ip);
                 }
                 if (!empty($location)) {
                     $result[self::COUNTRY_CODE_KEY] = $location[0];
                     $result[self::REGION_CODE_KEY] = $location[1];
                 }
                 break;
             case GEOIP_COUNTRY_EDITION:
                 // country database type
                 if ($isIPv6) {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr_v6($locationGeoIp, $ip);
                 } else {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip);
                 }
                 break;
             default:
                 // unknown database type, log warning and fallback to country edition
                 Log::warning("Found unrecognized database type: %s", $locationGeoIp->databaseType);
                 if ($isIPv6) {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr_v6($locationGeoIp, $ip);
                 } else {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip);
                 }
                 break;
         }
     }
     // NOTE: ISP & ORG require commercial dbs to test. The code has been tested manually,
     // but not by system tests.
     $ispGeoIp = $this->getGeoIpInstance($key = 'isp');
     if ($ispGeoIp) {
         if ($isIPv6) {
             $isp = geoip_name_by_addr_v6($ispGeoIp, $ip);
         } else {
             $isp = geoip_org_by_addr($ispGeoIp, $ip);
         }
         if (!empty($isp)) {
             $result[self::ISP_KEY] = utf8_encode($isp);
         }
     }
     $orgGeoIp = $this->getGeoIpInstance($key = 'org');
     if ($orgGeoIp) {
         if ($isIPv6) {
             $org = geoip_name_by_addr_v6($orgGeoIp, $ip);
         } else {
             $org = geoip_org_by_addr($orgGeoIp, $ip);
         }
         if (!empty($org)) {
             $result[self::ORG_KEY] = utf8_encode($org);
         }
     }
     if (empty($result)) {
         return false;
     }
     $this->completeLocationResult($result);
     return $result;
 }