1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var interfaces = require('os').networkInterfaces()
|
6 | var addresses = []
|
7 |
|
8 | function ip() {
|
9 | Object.keys(interfaces).forEach(function(name) {
|
10 | interfaces[name].forEach(function(node) {
|
11 | if (node.family === 'IPv4' && node.internal === false) {
|
12 | addresses.push(node)
|
13 | }
|
14 | })
|
15 | })
|
16 |
|
17 | // Might apply some algorithm to determin which addresss is the one accessable
|
18 | // by totoro server if there's multiple addresses found.
|
19 | //
|
20 | // Just use the one found first for now.
|
21 | if (addresses.length > 0) {
|
22 | return addresses[0].address
|
23 | }
|
24 | }
|
25 |
|
26 |
|
27 | console.log(ip())
|