forked from stjohnjohnson/postbin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpostbin.js
executable file
·45 lines (40 loc) · 1.28 KB
/
postbin.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
#!/usr/bin/env node
var http = require('http');
var os = require('os');
var ifaces = os.networkInterfaces();
var port = parseInt(process.argv[2]);
if (isNaN(port)) {
console.error('Usage: postbin.js PORT');
process.exit(1);
}
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
console.log('\n\n');
console.log('> ' + req.method + ' ' + req.url);
console.log('> Headers: ');
console.log(req.headers);
req.on('data', function (data) {
console.log('>> ' + data);
});
req.on('end', function () {
console.log('>>> EOL');
});
res.end('');
}).listen(port);
Object.keys(ifaces).forEach(function (ifname) {
var alias = 0;
ifaces[ifname].forEach(function (iface) {
if ('IPv4' !== iface.family || iface.internal !== false) {
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return;
}
if (alias >= 1) {
// this single interface has multiple ipv4 addresses
console.log(ifname + ':' + alias, 'http://' + iface.address + ':' + port);
} else {
// this interface has only one ipv4 adress
console.log(ifname, 'http://' + iface.address + ':' + port);
}
++alias;
});
});