-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (32 loc) · 899 Bytes
/
server.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
const express = require('express');
const ping = require('node-icmp-traceroute');
const PORT = 8080;
const HOST = '0.0.0.0';
const app = express();
// https://stackoverflow.com/questions/22381783/traceroute-why-my-packets-travel-around-the-world
app.get('/', (req, res) => {
res.send('hello');
});
app.get('/traceroute', (req, res) => {
const { ipToTraceroute } = req.query;
ping.createSession().traceRoute('google.com', (err, data) => {
if (err) {
if (err.name === 'DNSError') throw err;
} else {
console.log(
'[Inside app] data.latitude = ',
data.latitude,
' data.longitude = ',
data.longitude,
' data.source = ',
data.source,
' data.target = ',
data.target,
' status = ',
data.status,
);
}
});
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);