(targets)
| 164 | } |
| 165 | |
| 166 | function findInterfacesWin32 (targets) { |
| 167 | const output = cp.execSync('ipconfig /all', { stdio: 'pipe' }).toString() |
| 168 | |
| 169 | const interfaces = [] |
| 170 | const lines = output.split('\n') |
| 171 | let it = false |
| 172 | for (let i = 0; i < lines.length; i++) { |
| 173 | // Check if new device |
| 174 | let result |
| 175 | if (lines[i].substr(0, 1).match(/[A-Z]/)) { |
| 176 | if (it) { |
| 177 | if (targets.length === 0) { |
| 178 | // Not trying to match anything in particular, return everything. |
| 179 | interfaces.push(it) |
| 180 | } else { |
| 181 | for (let j = 0; j < targets.length; j++) { |
| 182 | const target = targets[j] |
| 183 | if (target === it.port.toLowerCase() || target === it.device.toLowerCase()) { |
| 184 | interfaces.push(it) |
| 185 | break |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | it = { |
| 192 | port: '', |
| 193 | device: '' |
| 194 | } |
| 195 | |
| 196 | const result = /adapter (.+?):/.exec(lines[i]) |
| 197 | if (!result) { |
| 198 | continue |
| 199 | } |
| 200 | |
| 201 | it.device = result[1] |
| 202 | } |
| 203 | |
| 204 | if (!it) { |
| 205 | continue |
| 206 | } |
| 207 | |
| 208 | // Try to find address |
| 209 | result = /Physical Address.+?:(.*)/mi.exec(lines[i]) |
| 210 | if (result) { |
| 211 | it.address = normalize(result[1].trim()) |
| 212 | it.currentAddress = it.address |
| 213 | continue |
| 214 | } |
| 215 | |
| 216 | // Try to find description |
| 217 | result = /description.+?:(.*)/mi.exec(lines[i]) |
| 218 | if (result) { |
| 219 | it.description = result[1].trim() |
| 220 | continue |
| 221 | } |
| 222 | } |
| 223 | return interfaces |
no test coverage detected