Skip to content

Instantly share code, notes, and snippets.

@asharirfan
Created August 9, 2018 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asharirfan/c41744e89127ac8c6b919ee88fbe34a8 to your computer and use it in GitHub Desktop.
Save asharirfan/c41744e89127ac8c6b919ee88fbe34a8 to your computer and use it in GitHub Desktop.
Query GeoIP Lookup of an IP Address using simple-geoip
// Include the package.
const simpleGeoIP = require('simple-geoip');
// Create a new instance of the package using your API key.
let geoIP = new simpleGeoIP('YOUR_API_KEY');
// Send a request for GeoIP lookup.
geoIP.lookup('8.8.8.8', (err, data) => {
if (err) throw err; // Look for errors (if any).
console.log(data); // Dump the results to the log.
});
// Sample response that you will get from the API.
{
"ip": "8.8.8.8",
"location": {
"country": "US",
"region": "California",
"city": "Mountain View",
"lat": 37.40599,
"lng": -122.078514,
"postalCode": "94043",
"timezone": "-08:00"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment