Im trying to implement a Network discovery search which returns all devices that are linked with my local network. My code so far looks like this:
const find = require('local-devices');
// Find all local network devices.
find().then(devices => {
console.log(devices);
})
And the returned array in the console looks like this:
[
{ name: '?', ip: '192.168.0.174', mac: '00:17:88:65:f4:4d' },
{ name: '?', ip: '192.168.0.222', mac: '80:be:05:73:bc:g5' },
{ name: '?', ip: '192.168.0.190', mac: '0c:fe:45:4d:b8:28' }
]
So, I know the Mac Adress of the device im looking for already, my problem is, how can I search for the mac adress in the Array, and return the specific ip Adress of this device? For example, I pass the mac adress "00:17:88:65:f4:4d" into a function, and the function should return "192.168.0.174" which I can save in a variable and work with in the following code.
I might be able to solve this with the find() function, but how can I tell the code, that I only want the ip adress, and not the full element of the array saved? I thought about something like:
const ip = devices.find('00:17:88:65:f4:4d');
But this would only return the full element, if the syntax was correct.
.then()callback, but you can't wrap that in a function that'd synchronously let you fetch a particular IP address.