diff --git a/README.md b/README.md index 26dbf783..44122883 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ an internal binary format (note that this is different from the binary data form binary file to lookup IP addresses and return the country, region and city that it maps to. Both IPv4 and IPv6 addresses are supported, however since the GeoLite IPv6 database does not currently contain any city or region -information, city and region lookups are only supported for IPv4. +information, city, region and postal code lookups are only supported for IPv4. philosophy ---------- @@ -45,11 +45,13 @@ var ip = "207.97.227.239"; var geo = geoip.lookup(ip); console.log(geo); -{ range: [ 3479299040, 3479299071 ], +{ range: [ 3479297920, 3479301339 ], country: 'US', - region: 'CA', - city: 'San Francisco', - ll: [37.7484, -122.4156] } + region: 'TX', + city: 'San Antonio', + ll: [ 29.4889, -98.3987 ], + metro: 641, + zip: 78218 } ``` installation @@ -95,7 +97,9 @@ If the IP address was found, the `lookup` method returns an object with the foll // ISO-3166-2 subcountry code for other countries, this is the // FIPS 10-4 subcountry code city: "City Name", // This is the full city name - ll: [, ] // The latitude and longitude of the city + ll: [, ], // The latitude and longitude of the city + metro: , // Metro code + zip: // Postal code (IPv4 only) } ``` diff --git a/data/geoip-city-names.dat b/data/geoip-city-names.dat index 857c16ff..77b17e61 100644 Binary files a/data/geoip-city-names.dat and b/data/geoip-city-names.dat differ diff --git a/data/geoip-city.dat b/data/geoip-city.dat index d2e587e1..039de36d 100644 Binary files a/data/geoip-city.dat and b/data/geoip-city.dat differ diff --git a/data/geoip-city6.dat b/data/geoip-city6.dat index 810918f8..34a5a226 100644 Binary files a/data/geoip-city6.dat and b/data/geoip-city6.dat differ diff --git a/data/geoip-country.dat b/data/geoip-country.dat index d1917e97..c85f34f1 100644 Binary files a/data/geoip-country.dat and b/data/geoip-country.dat differ diff --git a/data/geoip-country6.dat b/data/geoip-country6.dat index f1925123..3723cc8e 100644 Binary files a/data/geoip-country6.dat and b/data/geoip-country6.dat differ diff --git a/lib/geoip.js b/lib/geoip.js index 04732abe..29959b33 100644 --- a/lib/geoip.js +++ b/lib/geoip.js @@ -107,7 +107,8 @@ function lookup4(ip) { geodata.region = locBuffer.toString('utf8', (locId * locRecordSize) + 2, (locId * locRecordSize) + 4).replace(/\u0000.*/, ''); geodata.ll = [locBuffer.readInt32BE((locId * locRecordSize) + 4) / 10000, locBuffer.readInt32BE((locId * locRecordSize) + 8) / 10000]; geodata.metro = locBuffer.readInt32BE((locId * locRecordSize) + 12); - geodata.city = locBuffer.toString('utf8', (locId * locRecordSize) + 16, (locId * locRecordSize) + locRecordSize).replace(/\u0000.*/, ''); + geodata.zip = locBuffer.readInt32BE((locId * locRecordSize) + 16); + geodata.city = locBuffer.toString('utf8', (locId * locRecordSize) + 20, (locId * locRecordSize) + locRecordSize).replace(/\u0000.*/, ''); } return geodata; diff --git a/scripts/updatedb.js b/scripts/updatedb.js index 6a4d8801..c61f95ec 100644 --- a/scripts/updatedb.js +++ b/scripts/updatedb.js @@ -369,6 +369,7 @@ function processCityDataNames(src, dest, cb) { var cc = fields[1]; var rg = fields[2]; var city = fields[3]; + var zip = parseInt(fields[4]); var lat = Math.round(parseFloat(fields[5]) * 10000); var lon = Math.round(parseFloat(fields[6]) * 10000); var metro = parseInt(fields[7]); @@ -384,7 +385,11 @@ function processCityDataNames(src, dest, cb) { b.writeInt32BE(metro, 12); } - b.write(city, 16); + if(zip){ + b.writeInt32BE(zip, 16); + } + + b.write(city, 20); fs.writeSync(datFile, b, 0, b.length, null); }