-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexample.js
79 lines (65 loc) · 1.63 KB
/
example.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
68
69
70
71
72
73
74
75
76
77
78
79
const Grenache = require('grenache-nodejs-http')
const Link = require('grenache-nodejs-link')
const Peer = Grenache.PeerRPCClient
const link = new Link({
grape: 'http://127.0.0.1:30001'
})
link.start()
const secure = false
const serviceName = 'rest:util:net'
// ssl / fingerprint
// const fs = require('fs')
// const path = require('path')
// const serviceName = 'sec:rest:util:net'
// secure = {
// key: fs.readFileSync(path.join(__dirname, 'sec', 'client-key.pem')),
// cert: fs.readFileSync(path.join(__dirname, 'sec', 'client-crt.pem')),
// ca: fs.readFileSync(path.join(__dirname, 'sec', 'ca-crt.pem')),
// rejectUnauthorized: false // take care, can be dangerous in production!
// }
//
const opts = {}
if (secure) {
opts.secure = secure
}
const peer = new Peer(link, opts)
peer.init()
const geoQuery = {
action: 'getIpGeo',
args: ['8.8.8.8']
}
peer.request(serviceName, geoQuery, { timeout: 10000 }, (err, data) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log('getGeoIp data:')
console.log(data)
console.log('---')
})
const asnQuery = {
action: 'getIpAsn',
args: ['8.8.8.8']
}
peer.request(serviceName, asnQuery, { timeout: 10000 }, (err, data) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log('getIpAsn data:')
console.log(data)
console.log('---')
})
const generalQuery = {
action: 'getIpInfo',
args: ['8.8.8.8']
}
peer.request(serviceName, generalQuery, { timeout: 10000 }, (err, data) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log('getIpInfo data:')
console.log(JSON.stringify(data, null, ' '))
console.log('---')
})