UNPKG

729 BJavaScriptView Raw
1
2var spawn = require('child_process').spawn;
3
4initiator.Listener = function (config) {
5
6 var self = this;
7
8 // we need detectIP because by default httpd listen on 127.0.0.1
9 this.detectIP = function (cb) {
10
11 var child = spawn('ifconfig');
12
13 var stderr = '';
14 var stdout = '';
15
16 child.stdout.on('data', function (data) {
17 stdout += data;
18 });
19
20 child.stderr.on('data', function (data) {
21 stderr += data;
22 });
23
24 child.on('exit', function (code) {
25
26 try {
27 stdout.match (/^\s+inet\s+\d+\.\d+\.\d+\.\d+/mg).map (function (item) {
28 var ip = item.match (/\d+\.\d+\.\d+\.\d+/)[0];
29 if (ip != '127.0.0.1') {
30 throw ip;
31 }
32 });
33 } catch (e) {
34 self.host = e
35 }
36
37 cb.call (self);
38 });
39 }
40
41};