UNPKG

geoip-api

Version:

A library to ask several online geo-ip services for ip geo information

31 lines (25 loc) 838 B
Request = require 'request' Cheerio = require 'cheerio' class GeoIpToolHandler lookup: (ip, callback) -> time = Date.now() Request.get "http://www.geoiptool.com/en/?ip=#{ip}", (err, response, body) -> return callback(err) if err return callback('no response') if not body $ = Cheerio.load(body) country = $('.sidebar-data .data-item').eq(2).find('span').eq(1).text() countryCode = $('.sidebar-data .data-item').eq(3).find('span').eq(1).text() region = $('.sidebar-data .data-item').eq(4).find('span').eq(1).text() city = $('.sidebar-data .data-item').eq(5).find('span').eq(1).text() callback(null, { country: name: country code: countryCode city: city region: region }, { source: 'geoiptool' time: Date.now() - time ip: ip }) module.exports = new GeoIpToolHandler