New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

device-discovery

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

device-discovery - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

3

example.js

@@ -10,1 +10,4 @@ 'use strict'

// ...
discovery.on('done', () =>
console.log('Done!'))

20

index.js

@@ -14,24 +14,10 @@ 'use strict'

module.exports = ({
module.exports = ({ type = 'ICMP', iface = 'WiFi', start = 2, end = 254, port = 1, timeout = 3000, retries = 0, excludeSelf = true } = {}) => {
type = 'ICMP',
iface = 'WiFi',
start = 2,
end = 254,
port = 1,
timeout = 3000,
retries = 0
} = {}) => {
const address = getIfaceAddress(iface)
const range = getIfaceRange(address)
const scanner = getScanner(type)({ range, start, end, port, timeout, retries })
return scanner.on('hit', function ({ host }) {
let device = `${range}.${host}`
// exclude own device
if (device !== address) this.emit('device', device)
})
return getScanner(type)({ range, start, end, port, timeout, retries,
exclude: excludeSelf ? address : false })
}

@@ -5,26 +5,24 @@

const pingHost = ({ session, range, dest }) => {
module.exports = ({ range = '192.168.0', start = 2, end = 254, timeout = 3000, retries = 0, exclude = false } = {}) => {
return new Promise ((resolve, reject) => {
const emitter = new EventEmitter()
const session = ping.createSession({ timeout, retries })
let pending = 0
session.pingHost(`${range}.${dest}`, (error, target) => {
error ? reject(error) : resolve(target)
})
for (let i = start; i <= end; i++) {
})
pending++
const device = `${range}.${i}`
}
session.pingHost(device, error => {
if (!error && device !== exclude) emitter.emit('device', device)
if (!--pending) {
emitter.emit('done')
session.close()
}
})
}
module.exports = ({ range = '192.168.0', start = 2, end = 254, timeout = 1000, retries = 0 } = {}) => {
const emitter = new EventEmitter()
const session = ping.createSession({ timeout, retries })
for (let i = start; i <= end; i++)
pingHost({ session, range, dest: i })
.then(reason => emitter.emit('hit', { host: i, reason }))
.catch(reason => emitter.emit('miss', { host: i, reason }))
return emitter
}

@@ -6,36 +6,39 @@ 'use strict'

const scanHost = ({ range, dest, port, timeout }) => {
const scanHost = ({ device, port, timeout }, callback) => {
return new Promise ((resolve, reject) => {
const socket = new Socket()
socket.setTimeout(timeout)
socket.connect({ host: `${range}.${dest}`, port })
socket.connect({ host: device, port })
socket.unref()
socket.on('error', error =>
'ECONNREFUSED' === error.code ? resolve('REFUSED') : reject(error.code))
'ECONNREFUSED' === error.code ? callback(false) : callback(true))
socket.on('timeout', () => {
reject('TIMEOUT'); socket.destroy() })
callback(true); socket.destroy() })
socket.on('connect', () => {
resolve('CONNECTED'); socket.destroy() })
callback(false); socket.destroy() })
})
}
module.exports = ({ range = '192.168.0', start = 2, end = 254, port = 1, timeout = 3000 } = {}) => {
module.exports = ({ range = '192.168.0', start = 2, end = 254, port = 1, timeout = 3000, exclude = false } = {}) => {
const emitter = new EventEmitter()
let pending = 0
for (let i = start; i <= end; i++)
scanHost({ range, dest: i, port, timeout })
.then(reason => emitter.emit('hit', { host: i, reason }))
.catch(reason => emitter.emit('miss', { host: i, reason }))
for (let i = start; i <= end; i++) {
pending++
const device = `${range}.${i}`
scanHost({ device, port, timeout }, error => {
if (!error && device !== exclude) emitter.emit('device', device)
if (!--pending) emitter.emit('done')
})
}
return emitter
}
{
"version": "0.2.0",
"version": "0.3.0",
"name": "device-discovery",

@@ -4,0 +4,0 @@ "description": "Discover devices on your local network.",

@@ -24,2 +24,5 @@

discovery.on('done', () =>
console.log('Done!'))
```

@@ -39,5 +42,7 @@

- **retries** `<Number>`: *default =* `0`; the number of retries for pinning a host (`ICMP` only)
- **excludeSelf** `<Boolean>`: *default =* `true`; whether to exclude the device the discovery is run on
- **throws** an `<Error>` if the interface cannot be found or the type is unknown
- **returns** an `<EventEmitter>` with the following events:
- **device** => `<String>`: the IPv4 address of the device found
- **done** => `()`: if the discovery is done

@@ -44,0 +49,0 @@ ## License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc