3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00

better geoip

This commit is contained in:
reality 2016-04-11 18:08:20 +00:00
parent d19fc76088
commit bab36d5af3

View File

@ -3,7 +3,8 @@
* Description: Performs and reports on basic DNS functions. * Description: Performs and reports on basic DNS functions.
*/ */
var dnsm = require('dns'), var dnsm = require('dns'),
request = require('request'); request = require('request'),
http = require('http');
var dns = function(dbot) { var dns = function(dbot) {
var commands = { var commands = {
@ -31,11 +32,11 @@ var dns = function(dbot) {
'~geoip': function(event) { '~geoip': function(event) {
var ip = event.params[1]; var ip = event.params[1];
request.get('http://www.telize.com/geoip/'+ip, { request.get('http://ipinfo.io/'+ip, {
'json': true 'json': true
}, function(err, response, body) { }, function(err, res, body) {
if(!err && body && !_.has(body, 'code')) { if(!err && body) {
event.reply(ip + ' is located in '+ body.postal_code + ', ' + body.city + ', ' + body.country + ' and is hosted by ' + body.isp); event.reply(ip + ' is located in '+ body.city + ', ' + body.country + '. Hostname: ' + body.hostname + '. ISP: ' + body.org);
} else { } else {
event.reply('No info about ' + ip); event.reply('No info about ' + ip);
} }