-
Notifications
You must be signed in to change notification settings - Fork 0
/
otx_alientvautl_checkIP_and_Domain.js
42 lines (33 loc) · 1.28 KB
/
otx_alientvautl_checkIP_and_Domain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const request = require('request');
var otx_apikey = "";
function checkIP(ip){
var promise = new Promise(function(resolve, reject) {
if (otx_apikey == "") reject(Error("Please set the OTX alientvault API key"));
if (ip.indexOf(':') > -1){
ip_type = "IPv6"
}
else{
ip_type = "IPv4"
}
var url = 'https://otx.alienvault.com/api/v1/indicators/'+ip_type+'/'+ip+'/general';
request({url: url}, function (error, response, body) {
if (error) reject(Error("Error accessing otx.alienvault.com: "+error));
if (body) resolve(JSON.parse(body));
});
});
return promise;
}
function checkDomain(domain){
var promise = new Promise(function(resolve, reject) {
if (otx_apikey == "") reject(Error("Please set the OTX alientvault API key"));
var url = 'https://otx.alienvault.com/api/v1/indicators/domain/'+domain+'/general';
request({url: url}, function (error, response, body) {
if (error) reject(Error("Error accessing otx.alienvault.com: "+error));
if (body) resolve(JSON.parse(body));
});
});
return promise;
}
exports.setApiKey = function(key){ otx_apikey = key; }
exports.checkIP = checkIP;
exports.checkDomain = checkDomain;