-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomains.js
67 lines (66 loc) · 2.39 KB
/
domains.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
let http = require('http');
const log4js = require('./log4js');
const emailjs = require('./email');
const logger = log4js.logger_domains;
let domains = "www.taofenq.com,1.taofenquan11.com,www.baidu.com,c.com,d.com,e.com";
let lastDomains = domains.split(",");
logger.info('Start Scanner...');
let scannerInterval = setInterval(function(){
scanner(lastDomains[0]);
},5000);
function scanner(domain){
//console.log("检查域名:" + domain + "," + lastDomains.indexOf(domain));
let options = {
hostname: '1.com',
port: '80',
path: '/api/?token=50fe08567f49300279e7b22466bfc31d&url=http://'+domain,
timeout: 1500
};
const req = http.request(options, (res) => {
let serverData = "";
res.on('data',(chunk) => {
serverData += chunk;
});
res.on('end',() => {
parseApiResult(serverData,domain);
});
});
req.on('timeout', (res) => {
logger.error('Connect timeout from:'+options.hostname);
});
req.on('error', (e) => {
logger.error(e.name + ',message:'+ e.message);
});
req.end();
}
function parseApiResult(serverData,domain){
try{
//console.log(serverData);
var result = JSON.parse(serverData);
}catch(e){
logger.error(e.name + ":JSON parse error at domains.parseApiResult,message:" + e.message);
return;
}
if(result.code=='201'){
let index = lastDomains.indexOf(domain);
if(index>-1){
lastDomains.splice( index,1);
logger.info('remove : '+ domain + ', as the domain is banned.');
}
if(lastDomains.length == 0){
clearInterval(scannerInterval);
logger.info('All domains is banned, stop scanning.');
}
let total = domains.split(',').length;
if(lastDomains.length <= total / 2 ){
let message = '域名:'+ domain + '已被封,当前域名列表被封过半;当前域名情况:活跃:' + lastDomains.length + ',共:' + total;
emailjs.sendEmail('crelife@sina.com','域名列表被封过半警示',message);
}
}else if(result.code=='200'){
lastDomains.push(lastDomains.shift());
}else{
logger.warn('API is not reliable,the code is :' + result.code);
}
}
exports.lastDomains = lastDomains;
exports.domains = domains.split(",");