(targets)
| 105 | } |
| 106 | |
| 107 | function findInterfacesLinux (targets) { |
| 108 | // Parse the output of `ifconfig` which gives us: |
| 109 | // - the adapter description |
| 110 | // - the adapter name/device associated with this, if any, |
| 111 | // - the MAC address, if any |
| 112 | |
| 113 | let output = cp.execSync('ifconfig', { stdio: 'pipe' }).toString() |
| 114 | |
| 115 | const details = [] |
| 116 | while (true) { |
| 117 | const result = /(.*?)HWaddr(.*)/mi.exec(output) |
| 118 | if (!result || !result[1] || !result[2]) { |
| 119 | break |
| 120 | } |
| 121 | details.push(result[1], result[2]) |
| 122 | output = output.slice(result.index + result[0].length) |
| 123 | } |
| 124 | |
| 125 | const interfaces = [] |
| 126 | |
| 127 | for (let i = 0; i < details.length; i += 2) { |
| 128 | const s = details[i].split(':') |
| 129 | |
| 130 | let device, port |
| 131 | if (s.length >= 2) { |
| 132 | device = s[0].split(' ')[0] |
| 133 | port = s[1].trim() |
| 134 | } |
| 135 | |
| 136 | let address = details[i + 1].trim() |
| 137 | if (address) { |
| 138 | address = normalize(address) |
| 139 | } |
| 140 | |
| 141 | const it = { |
| 142 | address: address, |
| 143 | currentAddress: getInterfaceMAC(device), |
| 144 | device: device, |
| 145 | port: port |
| 146 | } |
| 147 | |
| 148 | if (targets.length === 0) { |
| 149 | // Not trying to match anything in particular, return everything. |
| 150 | interfaces.push(it) |
| 151 | continue |
| 152 | } |
| 153 | |
| 154 | for (let j = 0; j < targets.length; j++) { |
| 155 | const target = targets[j] |
| 156 | if (target === port.toLowerCase() || target === device.toLowerCase()) { |
| 157 | interfaces.push(it) |
| 158 | break |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return interfaces |
| 164 | } |
no test coverage detected