<NME> sample.js
<BEF> var geoip = require('geoip');

/*
 * Country geo infomation
 * The module has the GeoIP country data file within it,
 * so you don't need to download.
 * However you can always get the latest versioin by:
 * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
 */
var data = geoip.open();

geoip.country.code_by_addr(data, '8.8.8.8'); // prints 'US'
geoip.country.name_by_addr(data, '8.8.8.8'); // prints  'USA'
// ipv4 address lookup //
/////////////////////////
var Country = geoip.Country;
var country = new Country('/path/to/GeoIP.dat');

// Synchronous method:
var country_obj = country.lookupSync('8.8.8.8');

console.log(country_obj);
/*
{ country_code: 'US',
  country_code3: 'USA',
  country_name: 'United States',
  continent_code: 'NA'
}
*/

// Asynchronous method:
country.lookup('www.google.com', function(err, data) {
    if (err) {throw err;}
    if (data) { // if not found, just return null
      console.log(data);  // same as lookup method
    }
});

/////////////////////////
// ipv6 address lookup //
/////////////////////////
var Coutry6 = geoip.Country6;
var country_v6 = new Country6('/path/to/GeoIPv6.dat');

// Synchronous method
var country_obj_v6 = country_v6.lookupSync('2607:f0d0:1002:0051:0000:0000:0000:0004');

console.log(country_obj_v6);
/*
{ country_code: 'US',
  country_code3: 'USA',
  country_name: 'United States',
  continent_code: 'NA'
}
*/

country_v6.update('/path/to/new/country/ipv6/database');

// Asynchronous method
country_v6.lookup('2400:2352:b0f1:36c5:aa9d:694a:2f98:40bd', function(err, data_v6) {
    if (err) {throw err;}
    if (data_v6) {
      console.log(data_v6);
      /*
      {
        country_code: 'JP',
        country_code3: 'JPN',
        country_name: 'Japan',
        continent_code: 'AS'
      }
      */
    }
});


////////////////////////////////////////////////////////////////////////////////
// City
////////////////////////////////////////////////////////////////////////////////
//////////////////////////
// ipv4 address lookup ///
//////////////////////////
var City = geoip.City;
var city = new City('/path/to/GeoLiteCity.dat');

// Synchronous method
var city_obj = city.lookupSync('8.8.8.8');
console.log(city_obj);
/*
Return an object of city information
{
  "country_code":"US",
  "country_code3":"USA",
  "country_name":"United States",
  "continet_code":"NA",
  "region":"CA",
  "city":"Mountain View",
  "postal_code":"94043",
  "latitude":37.41919999999999,
  "longitude":-122.0574,
  "dma_code":807,
  "metro_code":807,
  "area_code":650
}
*/

city.update('/path/to/new/GeoLiteCity.dat');

// Asynchronous method
city.lookup('www.google.com', function(err, data) {
    if (err) {throw err;}
    if (data) {
      console.log(data);
    }
});

/////////////////////////
// ipv6 address lookup //
/////////////////////////
var City6 = geoip.City6;
var city6 = new City6('/path/to/GeoLiteCityv6.dat');

// Synchronous method
var city6_obj = city6.lookupSync('2002:a46f:f395:14de:f876:542b:41cb:5bbe');
console.log(city6_obj);
/*
Return an object of city information
{ country_code: 'US',
  country_code3: 'USA',
  country_name: 'United States',
  region: 'AL',
  city: 'Birmingham',
  postal_code: '35294',
  latitude: 33.54460144042969,
  longitude: -86.92919921875,
  continent_code: 'NA' }
*/

city6.update('/path/to/new/GeoLiteCityv6.dat');

// Asynchronous method
city6.lookup('2001:b565:487a:c05d:5f07:5662:c3cd:cfcf', function(err, data) {
    if (err) {throw err;}
    if (data) {
      console.log(data);
      /*
      { country_code: 'TW',
        country_code3: 'TWN',
        country_name: 'Taiwan',
        latitude: 23.5,
        longitude: 121,
        continent_code: 'AS'
      }
      */
    }
});


////////////////////////////////////////////////////////////////////////////////
// Organization
////////////////////////////////////////////////////////////////////////////////
var Org = geoip.Org;
var org = new Org('/path/to/database');  // Org module can open three edition database 'org', 'asnum', 'isp'

// Synchronous method
var org_str = org.lookup('8.8.8.8');

console.log(org_str);
/*
The type of returned data is string, for example:

'Genuity'
'AS15169 Google Inc.'

no longer an object
*/

org.update('/path/to/new/database');

// Asynchronous method
org.lookup('www.google.com', function(err, data) {
    if (err) {throw err;}
    if (data) {
      console.log(data);
    }
});


////////////////////////////////////////////////////////////////////////////////
// Region
////////////////////////////////////////////////////////////////////////////////
var Region = geoip.Region;
var region = new Region('/path/to/GeoIPRegion.dat');

// Synchronous method
var region_obj = region.lookupSync('8.8.8.8');

console.log(region_obj);
/*
region object has two properties:
{ country_code: 'US', region: 'CO' }

*/

region.update('/path/to/new/GeoIPRegion.dat');

// Asynchronous method
region.lookup('www.google.com', function(data) {
    if (data) {
      console.log(data);
    }
});


////////////////////////////////////////////////////////////////////////////////
// NetSpeed
////////////////////////////////////////////////////////////////////////////////
var NetSpeed = geoip.NetSpeed;
var netspeed = new NetSpeed('/path/to/GeoIPNetSpeed.dat');

// Synchronous method
var netspeed_str = netspeed.lookupSync('8.8.8.8');

console.log(netspeed_str);
/*
netspeed_str just a simple string, 'Dialup', 'Corprate'... so on
*/

netspeed.update('/path/to/new/netspeed/database');

// Asynchronous method
netspeed.lookup('www.google.com', function(err, data) {
    if (err) {throw err;}
    if (data) {
      console.log(data);  // Maybe return 'unknow' or different from lookup method
    }
});

<MSG> no binary file

<DFF> @@ -2,12 +2,10 @@ var geoip = requires('geoip');
 
 /*
  * Country geo infomation
- * The module has the GeoIP country data file within it,
- * so you don't need to download.
- * However you can always get the latest versioin by:
+ * You can always get the latest versioin of GeoIP.dat by:
  * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
  */
-var data = geoip.open();
+var data = geoip.open('/path/to/GeoIP.dat');
 
 geoip.country.code_by_addr(data, '8.8.8.8'); // prints 'US'
 geoip.country.name_by_addr(data, '8.8.8.8'); // prints  'USA'

{'commit': "diff --git a/.gitignore b/.gitignore\nindex 6005d33..14500c2 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -32,3 +32,6 @@ fabfile.*\n # no php file\n *.php\n *.inc\n+\n+# binary file\n+*.dat\ndiff --git a/README.md b/README.md\nindex 5281db3..17bc2bb 100644\n--- a/README.md\n+++ b/README.md\n@@ -3,8 +3,12 @@\n ###Data###\n \n Befor you can use this package, you need to download or buy some data from www.maxmind.com.\n-There are two free versions data among with some commercial versions.\n-For convenience, this package includes a free version of GeoIP country data file.\n+There are two free versions data among with some commercial version.\n+GeoIP.dat for country information and GeoLiteCity.dat for City information.\n+They are free for download.\n+You can get the detail from http://www.maxmind.com/app/geolitecountry\n+and http://www.maxmind.com/app/geolitecity.\n+        \n \n ###Install###\n \n@@ -15,7 +19,7 @@ For convenience, this package includes a free version of GeoIP country data file\n ####Country Information#####\n \n * Open the country data file\n-    var data = geoip.open();\n+    var data = geoip.open('/path/to/GeoIP.dat');\n \n * Synchronous methods, network independence.\n     geoip.country.code_by_addr(data, '8.8.8.8'); // prints 'US'\ndiff --git a/sample/geoip.js b/sample/geoip.js\nnew file mode 100644\nindex 0000000..c8689b2\n--- /dev/null\n+++ b/sample/geoip.js\n@@ -0,0 +1,50 @@\n+var geoip = requires('geoip');\n+\n+/*\n+ * Country geo infomation\n+ * The module has the GeoIP country data file within it,\n+ * so you don't need to download.\n+ * However you can always get the latest versioin by:\n+ * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz\n+ */\n+var data = geoip.open();\n+\n+geoip.country.code_by_addr(data, '8.8.8.8'); // prints 'US'\n+geoip.country.name_by_addr(data, '8.8.8.8'); // prints  'USA'\n+\n+geoip.country.code_by_domain(data, 'www.google.com', function(err, code) {\n+    if (err) {throw err;}\n+    console.log(code);  // prints 'US'\n+});\n+geoip.country.name_by_domain(data, 'www.google.com', function(err, name) {\n+    if (err) {throw err;}\n+    console.log(name);  // prints 'USA'\n+});\n+\n+/*\n+ * City geo infomation\n+ *\n+ * Befor you can use city geo information,\n+ * you need download GeoLiteCity.dat file first.\n+ * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz\n+ */\n+\n+var data = geoip.open('/path/to/GeoLiteCity.dat');\n+\n+geoip.city.record_by_addr(data, '8.8.8.8');\n+    //{ \n+    //country_code: 'US',\n+    //country_code3: 'USA',\n+    //country_name: 'United States',\n+    //continet_code: 'NA',\n+    //region: 'CA',\n+    //city: 'Mountain View',\n+    //postal_code: '94043',\n+    //latitude: 37.41919999999999,\n+    //longitude: -122.0574,\n+    //dma_code: 807,\n+    //metro_code: 807,\n+    //area_code: 650 \n+    //}\n+\n+GeoIP api for node.js, ported from GeoIP php api.\ndiff --git a/sample/sample.js b/sample/sample.js\nindex 1306ec2..894141a 100644\n--- a/sample/sample.js\n+++ b/sample/sample.js\n@@ -2,12 +2,10 @@ var geoip = requires('geoip');\n \n /*\n  * Country geo infomation\n- * The module has the GeoIP country data file within it,\n- * so you don't need to download.\n- * However you can always get the latest versioin by:\n+ * You can always get the latest versioin of GeoIP.dat by:\n  * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz\n  */\n-var data = geoip.open();\n+var data = geoip.open('/path/to/GeoIP.dat');\n \n geoip.country.code_by_addr(data, '8.8.8.8'); // prints 'US'\n geoip.country.name_by_addr(data, '8.8.8.8'); // prints  'USA'\n", 'commit_subject': 'no binary file', 'repo_name': 'kuno/GeoIP', 'committer': {'name': 'kuno', 'email': '2a84ebf639691a5074794bea52101d3b9e532f66@gmail.com', 'time_sec': '1290675463', 'tz_offset': '480', 'date': {'seconds': '1290675463'}}, 'commit_tree': 'b5c63017db5850e6308d350be0cb11a74becd8ee', 'commit_message': 'no binary file\n', 'language_name': 'C++', 'license': 'lgpl-2.1', 'hunks': "@@ -2,12 +2,10 @@ var geoip = requires('geoip');\n \n /*\n  * Country geo infomation\n- * The module has the GeoIP country data file within it,\n- * so you don't need to download.\n- * However you can always get the latest versioin by:\n+ * You can always get the latest versioin of GeoIP.dat by:\n  * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz\n  */\n-var data = geoip.open();\n+var data = geoip.open('/path/to/GeoIP.dat');\n \n geoip.country.code_by_addr(data, '8.8.8.8'); // prints 'US'\n geoip.country.name_by_addr(data, '8.8.8.8'); // prints  'USA'\n", 'addition_count': 2, 'deletion_count': 4, 'src_file': 'a/sample/sample.js', 'tgt_file': 'b/sample/sample.js', 'file_extension': '.js', 'before_file': 'var geoip = require(\'geoip\');\n\n/*\n * Country geo infomation\n * The module has the GeoIP country data file within it,\n * so you don\'t need to download.\n * However you can always get the latest versioin by:\n * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz\n */\nvar data = geoip.open();\n\ngeoip.country.code_by_addr(data, \'8.8.8.8\'); // prints \'US\'\ngeoip.country.name_by_addr(data, \'8.8.8.8\'); // prints  \'USA\'\n// ipv4 address lookup //\n/////////////////////////\nvar Country = geoip.Country;\nvar country = new Country(\'/path/to/GeoIP.dat\');\n\n// Synchronous method:\nvar country_obj = country.lookupSync(\'8.8.8.8\');\n\nconsole.log(country_obj);\n/*\n{ country_code: \'US\',\n  country_code3: \'USA\',\n  country_name: \'United States\',\n  continent_code: \'NA\'\n}\n*/\n\n// Asynchronous method:\ncountry.lookup(\'www.google.com\', function(err, data) {\n    if (err) {throw err;}\n    if (data) { // if not found, just return null\n      console.log(data);  // same as lookup method\n    }\n});\n\n/////////////////////////\n// ipv6 address lookup //\n/////////////////////////\nvar Coutry6 = geoip.Country6;\nvar country_v6 = new Country6(\'/path/to/GeoIPv6.dat\');\n\n// Synchronous method\nvar country_obj_v6 = country_v6.lookupSync(\'2607:f0d0:1002:0051:0000:0000:0000:0004\');\n\nconsole.log(country_obj_v6);\n/*\n{ country_code: \'US\',\n  country_code3: \'USA\',\n  country_name: \'United States\',\n  continent_code: \'NA\'\n}\n*/\n\ncountry_v6.update(\'/path/to/new/country/ipv6/database\');\n\n// Asynchronous method\ncountry_v6.lookup(\'2400:2352:b0f1:36c5:aa9d:694a:2f98:40bd\', function(err, data_v6) {\n    if (err) {throw err;}\n    if (data_v6) {\n      console.log(data_v6);\n      /*\n      {\n        country_code: \'JP\',\n        country_code3: \'JPN\',\n        country_name: \'Japan\',\n        continent_code: \'AS\'\n      }\n      */\n    }\n});\n\n\n////////////////////////////////////////////////////////////////////////////////\n// City\n////////////////////////////////////////////////////////////////////////////////\n//////////////////////////\n// ipv4 address lookup ///\n//////////////////////////\nvar City = geoip.City;\nvar city = new City(\'/path/to/GeoLiteCity.dat\');\n\n// Synchronous method\nvar city_obj = city.lookupSync(\'8.8.8.8\');\nconsole.log(city_obj);\n/*\nReturn an object of city information\n{\n  "country_code":"US",\n  "country_code3":"USA",\n  "country_name":"United States",\n  "continet_code":"NA",\n  "region":"CA",\n  "city":"Mountain View",\n  "postal_code":"94043",\n  "latitude":37.41919999999999,\n  "longitude":-122.0574,\n  "dma_code":807,\n  "metro_code":807,\n  "area_code":650\n}\n*/\n\ncity.update(\'/path/to/new/GeoLiteCity.dat\');\n\n// Asynchronous method\ncity.lookup(\'www.google.com\', function(err, data) {\n    if (err) {throw err;}\n    if (data) {\n      console.log(data);\n    }\n});\n\n/////////////////////////\n// ipv6 address lookup //\n/////////////////////////\nvar City6 = geoip.City6;\nvar city6 = new City6(\'/path/to/GeoLiteCityv6.dat\');\n\n// Synchronous method\nvar city6_obj = city6.lookupSync(\'2002:a46f:f395:14de:f876:542b:41cb:5bbe\');\nconsole.log(city6_obj);\n/*\nReturn an object of city information\n{ country_code: \'US\',\n  country_code3: \'USA\',\n  country_name: \'United States\',\n  region: \'AL\',\n  city: \'Birmingham\',\n  postal_code: \'35294\',\n  latitude: 33.54460144042969,\n  longitude: -86.92919921875,\n  continent_code: \'NA\' }\n*/\n\ncity6.update(\'/path/to/new/GeoLiteCityv6.dat\');\n\n// Asynchronous method\ncity6.lookup(\'2001:b565:487a:c05d:5f07:5662:c3cd:cfcf\', function(err, data) {\n    if (err) {throw err;}\n    if (data) {\n      console.log(data);\n      /*\n      { country_code: \'TW\',\n        country_code3: \'TWN\',\n        country_name: \'Taiwan\',\n        latitude: 23.5,\n        longitude: 121,\n        continent_code: \'AS\'\n      }\n      */\n    }\n});\n\n\n////////////////////////////////////////////////////////////////////////////////\n// Organization\n////////////////////////////////////////////////////////////////////////////////\nvar Org = geoip.Org;\nvar org = new Org(\'/path/to/database\');  // Org module can open three edition database \'org\', \'asnum\', \'isp\'\n\n// Synchronous method\nvar org_str = org.lookup(\'8.8.8.8\');\n\nconsole.log(org_str);\n/*\nThe type of returned data is string, for example:\n\n\'Genuity\'\n\'AS15169 Google Inc.\'\n\nno longer an object\n*/\n\norg.update(\'/path/to/new/database\');\n\n// Asynchronous method\norg.lookup(\'www.google.com\', function(err, data) {\n    if (err) {throw err;}\n    if (data) {\n      console.log(data);\n    }\n});\n\n\n////////////////////////////////////////////////////////////////////////////////\n// Region\n////////////////////////////////////////////////////////////////////////////////\nvar Region = geoip.Region;\nvar region = new Region(\'/path/to/GeoIPRegion.dat\');\n\n// Synchronous method\nvar region_obj = region.lookupSync(\'8.8.8.8\');\n\nconsole.log(region_obj);\n/*\nregion object has two properties:\n{ country_code: \'US\', region: \'CO\' }\n\n*/\n\nregion.update(\'/path/to/new/GeoIPRegion.dat\');\n\n// Asynchronous method\nregion.lookup(\'www.google.com\', function(data) {\n    if (data) {\n      console.log(data);\n    }\n});\n\n\n////////////////////////////////////////////////////////////////////////////////\n// NetSpeed\n////////////////////////////////////////////////////////////////////////////////\nvar NetSpeed = geoip.NetSpeed;\nvar netspeed = new NetSpeed(\'/path/to/GeoIPNetSpeed.dat\');\n\n// Synchronous method\nvar netspeed_str = netspeed.lookupSync(\'8.8.8.8\');\n\nconsole.log(netspeed_str);\n/*\nnetspeed_str just a simple string, \'Dialup\', \'Corprate\'... so on\n*/\n\nnetspeed.update(\'/path/to/new/netspeed/database\');\n\n// Asynchronous method\nnetspeed.lookup(\'www.google.com\', function(err, data) {\n    if (err) {throw err;}\n    if (data) {\n      console.log(data);  // Maybe return \'unknow\' or different from lookup method\n    }\n});\n', 'message': 'no binary file\n', 'author_name': 'kuno', 'lang': 'js'}