-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcap2hep.js
executable file
·86 lines (75 loc) · 2.77 KB
/
pcap2hep.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
80
81
82
83
84
85
86
#!/usr/bin/nodejs
/* WS to UDP Proxy for HEP */
/* HEP Hackaton */
if(process.argv.indexOf("-h") != -1){
console.log('Browser PCAP to HEP Mopster. For more information please visit: http://sipcapture.org ');
console.log('Usage:');
console.log();
console.log(' -w: HEP3 Websocket Port (8060)');
console.log(' -W: HEP3 Web Port (5000)');
console.log(' -s: HEP3 Collector IP (127.0.0.1)');
console.log(' -p: HEP3 Collector Port (9060)');
console.log(' -i: HEP3 Agent ID');
console.log();
console.log(' -debug: Debug Internals (ie: -debug true)');
console.log(' CRTL-C: Exit');
console.log();
process.exit();
}
/* Settings Section */
var settings = { debug: false, hep_server: '127.0.0.1', hep_port: 9060, hep_id: 8080, wss_port: 8060, web_port: 5000 };
if(process.argv.indexOf("-debug") != -1){
settings.debug = process.argv[process.argv.indexOf("-debug") + 1];
}
if(process.argv.indexOf("-s") != -1){
settings.hep_server = process.argv[process.argv.indexOf("-s") + 1];
}
if(process.argv.indexOf("-p") != -1){
settings.hep_port = process.argv[process.argv.indexOf("-p") + 1];
}
if(process.argv.indexOf("-w") != -1){
settings.wss_port = process.argv[process.argv.indexOf("-w") + 1];
}
if(process.argv.indexOf("-W") != -1){
settings.web_port = process.argv[process.argv.indexOf("-W") + 1];
}
if(process.argv.indexOf("-i") != -1){
settings.hep_id = process.argv[process.argv.indexOf("-i") + 1];
}
/* Required Modules */
var HEP = require('hep-js');
const fastify = require('fastify')()
const path = require('path')
//var Buffer = require('buffer').Buffer;
var dgram = require('dgram');
var WebSocketServer = require('ws').Server;
// Web Service
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'public')
})
fastify.get('/', function (req, reply) {
reply.sendFile('index.html')
})
fastify.listen(settings.web_port, '0.0.0.0', (err, address) => {
if (err) throw err
console.log("server listening: "+address)
})
// Websocket Service
var wss = new WebSocketServer({port: 8060});
//The ip & port of the udp server
var SERVER_IP = settings.hep_server || '127.0.0.1'
var SERVER_PORT = settings.hep_port || 9060
var udpClient;
wss.on('connection', function(ws) {
udpClient = dgram.createSocket('udp4');
//When a message is received from udp server send it to the ws client
udpClient.on('message', function(msg, rinfo) {
ws.send(msg);
});
//When a message is received from ws client send it to udp server.
ws.on('message', function(message) {
if(settings.debug) try { console.log(HEP.decapsulate(message)); } catch(e) { console.log(e); }
if (packet && packet.length) udpClient.send(packet, 0, packet.length, SERVER_PORT, SERVER_IP);
return;
});
});