public function geoip_org_by_addr($addr) { return geoip_name_by_addr($addr); }
function geoip_org_by_addr($gi, $addr) { return geoip_name_by_addr($gi, $addr); }
#!/usr/bin/php -q <?php include "geoip.inc"; $gi = geoip_open("/usr/local/share/GeoIP/GeoIPNetSpeedCell.dat", GEOIP_STANDARD); $netspeed = geoip_name_by_addr($gi, "24.24.24.24"); print $netspeed . "\n"; geoip_close($gi);
if ($routes[$i]->in_bgp) { $asn_data = $routes[$i]; break; } } // $prefix=$asn_data->prefix; $origin = $asn_data->origin; $asn_name = $asn_data->asn_name; $country = $geoloc_data->country; break; case "maxmind": default: $ip_parts = explode("/", $ip); $ip_start = $ip_parts[0]; if (strpos($ip_start, ".") !== false) { $asn = geoip_name_by_addr($giasn, $ip_start); } else { $asn = geoip_name_by_addr_v6($giasn_v6, $ip_start); } $asn_details = explode(" ", $asn); $origin = str_replace("AS", "", $asn_details[0]); array_shift($asn_details); $asn_name = implode(" ", $asn_details); if (strpos($ip_start, ".") !== false) { $country = geoip_country_code_by_addr($gi, $ip_start); } else { $country = geoip_country_code_by_addr_v6($gi_v6, $ip_start); } } $records++; if ($records > 1) {
#!/usr/bin/php -q <?php echo "http://code.google.com/p/fast-flux/\n"; echo "(C) 2013 Adam Ziaja <*****@*****.**> http://adamziaja.com\n"; $domain = $argv[1]; include_once 'geoip.inc'; // https://raw.github.com/maxmind/geoip-api-php/master/geoip.inc try { $db = new PDO('mysql:host=localhost;dbname=botnet;charset=utf8', 'LOGIN', 'PASSWORD'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->query('CREATE TABLE IF NOT EXISTS botnet (botnet_ip VARCHAR(15) NOT NULL UNIQUE, botnet_datetime DATETIME NOT NULL, botnet_country TEXT, botnet_asn TEXT)'); } catch (PDOException $e) { print 'Exception : ' . $e->getMessage(); } while (1) { $time = date("Y-m-d H:i:s"); $ip = gethostbyname($domain); if (filter_var($ip, FILTER_VALIDATE_IP)) { $country = strtolower(geoip_country_code_by_name($ip)); $asn = htmlspecialchars(geoip_name_by_addr(geoip_open('/usr/share/GeoIP/GeoIPASNum.dat', GEOIP_STANDARD), $ip), ENT_QUOTES); echo "{$domain} {$ip}\n"; try { $db->query("INSERT IGNORE INTO botnet (botnet_ip, botnet_datetime, botnet_country, botnet_asn) VALUES ('{$ip}', '{$time}', '{$country}', '{$asn}')"); } catch (PDOException $e) { print 'Exception : ' . $e->getMessage(); } } }
public function processIP($ip) { // setup the default marketo bject $request = Config::inst()->get('DefaultMarketoResponse', 'request'); $statusArray = Config::inst()->get('DefaultMarketoResponse', 'status'); $result = Config::inst()->get('DefaultMarketoResponse', 'result'); $status = null; $path = Config::inst()->get('IPInfoCache', 'GeoPathCity'); if (!$path) { $path = $this->defaultPath; } if (!file_exists($path)) { user_error('Error loading Geo database', E_USER_ERROR); } $request['ip'] = $ip; $request['type'] = MarketoRegionalDriver::ipVersion($ip); if ($request['type'] == 'IPv4') { $isPrivate = MarketoRegionalDriver::isPrivateIP($ip); if ($isPrivate) { $status = self::setStatus('IP_ADDRESS_RESERVED', null, $status); } $geo = geoip_open($path, GEOIP_STANDARD); $record = geoip_record_by_addr($geo, $ip); } else { /* Will add IPv6 checking later $path = '/usr/share/GeoIP/GeoLiteCityv6.dat'; $geo = geoip_open($path, GEOIP_STANDARD); $record = geoip_record_by_addr_v6($geo, $ip); */ } $countryCode = null; if ($record && is_object($record)) { try { $result['location']['continent_code'] = $record->continent_code; // fetch continent by continent_code //$result['location']['continent_names'] = $record->continent->names; $countryCode = $record->country_code; $result['location']['country_code'] = $countryCode; //$result['location']['country_names'] = $record->country->names; $result['location']['postal_code'] = $record->postal_code; $result['location']['city_name'] = $record->city; $result['location']['latitude'] = $record->latitude; $result['location']['longitude'] = $record->longitude; // get timezone from region code //$result['location']['time_zone'] = $record->location->timeZone; } catch (Exception $e) { $status = self::setStatus('GEOIP_EXCEPTION', $e, $status); } } $geoRegion = null; if ($countryCode) { $geoRegion = GeoRegion::get()->filter('RegionCode', $countryCode)->first(); if ($geoRegion && $geoRegion->exists()) { $result['location']['marketo_region_name'] = $geoRegion->Name; $result['location']['marketo_region_code'] = $geoRegion->RegionCode; $result['location']['marketo_region_time_zone'] = $geoRegion->TimeZone; } } // fetch ISP details $pathISP = Config::inst()->get('IPInfoCache', 'GeoPathISP'); if (!$pathISP) { $path = $this->defaultPathISP; } if (!file_exists($pathISP)) { user_error('Error loading Geo ISP database', E_USER_ERROR); } $isp = geoip_open($pathISP, GEOIP_STANDARD); if ($request['type'] == 'IPv4') { $record = geoip_name_by_addr($isp, $ip); } else { /* Will add IPv6 checking later $record = geoip_name_by_addr_v6($isp, $ip); */ } if ($record) { $result['organization']['isp'] = $record; } if ($status) { $statusArray['code'] = self::setStatus(null, null, $status); $statusArray['message'] = self::getStatusMessage($status); // do not cache a failure $this->json = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => $result)); return null; } else { // return cached success message $statusArray['code'] = self::setStatus('SUCCESS_CACHED', null, $status); $statusArray['message'] = self::getStatusMessage($status); $this->json = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => $result)); } // we write a different json object with a cached status to the DB $statusArray['code'] = self::setStatus('SUCCESS', null); $statusArray['message'] = self::getStatusMessage($statusArray['code']); $dbJson = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => $result)); return $dbJson; }