-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·32 lines (30 loc) · 913 Bytes
/
index.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
#!/usr/bin/env node
const os = require('os')
const ifaces = os.networkInterfaces()
const clipboardy = require('clipboardy')
const ips = Object.keys(ifaces).reduce((arr, ifname) => {
const alias = 0
ifaces[ifname].forEach((iface) => {
if ('IPv4' !== iface.family || iface.internal !== false) {
return
}
if (alias >= 1) {
// this single interface has multiple ipv4 addresses
arr.pushr({ name: `${ifname}:${alias}`, address: iface.address })
}
else {
// this interface has only one ipv4 adress
arr.push({ name: ifname, address: iface.address })
}
})
return arr
}, [])
ips.forEach((i) => {
if (i.address.indexOf('17.') === 0) {
console.log(`${i.address} (copied to the clipboard)`)
clipboardy.writeSync(i.address)
}
else {
console.log(i.address)
}
})