3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 12:42:51 +01:00
dbot/modules/dns/dns.js

97 lines
3.3 KiB
JavaScript
Raw Normal View History

2013-03-21 19:29:18 +01:00
/**
* Module Name: DNS
* Description: Performs and reports on basic DNS functions.
*/
2015-10-20 20:26:39 +02:00
var dnsm = require('dns'),
2016-04-11 20:08:20 +02:00
request = require('request'),
http = require('http');
2013-03-21 19:29:18 +01:00
var dns = function(dbot) {
2016-04-11 20:15:10 +02:00
if(!_.has(dbot.db, 'ip')) {
dbot.db.ip = {};
}
var ips = dbot.db.ip;
2016-04-11 20:23:02 +02:00
this.api = {
'getGeoIp': function(ip, callback) {
if(_.has(ips, ip)) {
body = ips[ip];
callback(ip + ' is located in '+ body.city + ', ' + body.country + '. Hostname: ' + body.hostname + '. ISP: ' + body.org);
} else {
request.get('http://ipinfo.io/'+ip, {
'json': true
}, function(err, res, body) {
if(!err && body) {
callback(ip + ' is located in '+ body.city + ', ' + body.country + '. Hostname: ' + body.hostname + '. ISP: ' + body.org);
} else {
callback('No info about ' + ip);
}
ips[ip] = body;
});
}
}.bind(this)
};
2013-03-21 19:29:18 +01:00
var commands = {
'~lookup': function(event) {
domain = event.params[1];
2015-10-20 20:26:39 +02:00
dnsm.lookup(domain, function (error, addr) {
2013-03-21 19:29:18 +01:00
if (error) {
event.reply(dbot.t("lookup-error",{"domain": domain, "code": error.code}));
} else {
event.reply(dbot.t("lookup",{"domain": domain, "address": addr}));
}
});
},
2013-06-27 20:26:54 +02:00
2013-03-21 19:29:18 +01:00
'~rdns': function(event) {
ip = event.params[1];
2015-10-20 20:26:39 +02:00
dnsm.reverse(ip, function (error, domain) {
if (error) {
event.reply(dbot.t("rdns-error",{"domain": domain, "ip": ip, "error": error.code}));
} else {
2013-03-21 19:29:18 +01:00
event.reply(dbot.t("rdns",{"domain": domain, "ip": ip}));
}
});
2015-02-15 19:26:25 +01:00
},
'~geoip': function(event) {
2016-04-11 20:08:20 +02:00
var ip = event.params[1];
2016-04-11 20:23:02 +02:00
this.api.getGeoIp(ip, function(result) { event.reply(result); });
2015-10-20 20:22:40 +02:00
},
'~dnsbl': function(event) {
2015-10-20 20:29:05 +02:00
var revIp = event.input[1].trim().split('.').reverse().join('.');
2015-10-20 20:26:39 +02:00
dnsm.lookup(revIp + '.cbl.abuseat.org', function(err, res) {
2015-10-20 20:22:40 +02:00
if(!err && res) {
2015-10-20 20:29:05 +02:00
event.reply(event.input[1] + ' is listed as an abusive IP.');
2015-10-20 20:22:40 +02:00
} else {
2015-10-20 20:29:05 +02:00
event.reply(event.input[1] + ' does not seem to be a Naughty Nancy.');
2015-10-20 20:22:40 +02:00
}
});
2013-03-21 19:29:18 +01:00
}
};
2015-10-20 20:30:15 +02:00
commands['~dnsbl'].regex = [/^dnsbl ([\d\w\s\.-]*)/, 2];
2013-03-21 19:29:18 +01:00
this.commands = commands;
2015-10-20 20:58:04 +02:00
if(dbot.config.modules.dns.dnsblconn == true) {
2015-10-20 20:56:00 +02:00
this.listener = function(event) {
if(event.message.match('CLICONN')) {
var ip = event.message.match('CLICONN ([^ ]+).*?((?:[0-9]{1,3}\.){3}[0-9]{1,3}) users');
revIp = ip[2].trim().split('.').reverse().join('.');
2015-10-20 20:59:55 +02:00
dbot.say(event.server, '#dnsbl', 'DEBUG: Looking up ' + ip[2] + ' for ' + ip[1] + ' @ ' + revIp);
2015-10-20 20:56:00 +02:00
dnsm.lookup(revIp + '.cbl.abuseat.org', function(err, res) {
if(!err && res) {
dbot.say(event.server, '#dnsbl', 'ALERT: ' + ip[1] + ' connecting from ' + ip[2] + ' may well be NAUGHTY.');
}
});
}
}
this.on = 'NOTICE';
}
2013-03-21 19:29:18 +01:00
};
exports.fetch = function(dbot) {
return new dns(dbot);
};