forked from wigy-opensource-developer/hydra-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (35 loc) · 1.21 KB
/
app.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 Crawler = require('./src/crawler')
const { URL } = require('url')
const { forEach, keys } = require('lodash')
const crawler = new Crawler()
const args = process.argv.slice(2)
const report = (crawler) => {
let blockStats = {}
forEach(crawler.heights, (item) => {
if (blockStats[item.height]) {
blockStats[item.height].count += 1
blockStats[item.height].ids[item.id] += 1
} else {
blockStats[item.height] = {}
blockStats[item.height].count = 1
blockStats[item.height].ids = {}
blockStats[item.height].ids[item.id] = 1
}
})
console.log(`===========================================`)
console.log(`Total nodes visited: ${keys(crawler.nodes).length}`)
console.log(`Total nodes online: ${crawler.heights.length}`)
console.log(`------------------------------------------`)
console.log(`Block stats:`)
console.log(blockStats)
console.log(`------------------------------------------`)
console.log(`Finished scanning in ${new Date() - crawler.startTime}ms`)
process.exit(0)
}
let node = {ip: '167.99.243.111', port: 4003}
if (args.length === 1) {
const url = new URL(args[0])
node.ip = url.hostname
node.port = url.port
}
crawler.run(node).then(report)