You are here

function drush_ip2country_lookup in IP-based Determination of a Visitor's Country 7

Same name and namespace in other branches
  1. 8 ip2country.drush.inc \drush_ip2country_lookup()

Implements drush_hook_COMMAND() for the ip2country-lookup command.

Gets the ISO 3166 2-character country code from the IP address.

Parameters

string|int $ip_address: IP address either as a dotted quad string (e.g. '127.0.0.1') or as a 32-bit unsigned long integer.

File

./ip2country.drush.inc, line 174

Code

function drush_ip2country_lookup($ip_address) {
  $country_code = ip2country_get_country($ip_address);
  if ($country_code == FALSE) {
    drush_print(dt('IP address not found in the database.'));
  }
  else {
    $country_list = country_get_list();
    $country_name = $country_list[$country_code];
    return array(
      $ip_address => array(
        'ip_address' => $ip_address,
        'name' => (string) dt($country_name),
        'country_code_iso2' => $country_code,
      ),
    );
  }
}