Update, insert new ping method

Took 29 minutes
This commit is contained in:
2021-08-27 08:30:39 +02:00
parent ecb804fe4c
commit cf29acee58
143 changed files with 14731 additions and 2 deletions

41
node_modules/local-devices/CHANGES.md generated vendored Normal file
View File

@ -0,0 +1,41 @@
# Local-Devices
All notable changes to this project will be documented here. The format is based
on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project
adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [3.1.0] - 2020-09-25
### Added
- support passing ip ranges to the `find` api ([#24](https://github.com/DylanPiercey/local-devices/pull/24))
## [3.0.0] - 2019-10-29
### Changed
⚠ BREAKING CHANGES
- dropping Node v8 support because [end-of-life](https://github.com/nodejs/Release#release-schedule)
[[#18](https://github.com/DylanPiercey/local-devices/pull/18)]
### Fixes
- increase `maxBuffer` of `cp.exec` to 10MB (1024*1024*10), fixes [#10](https://github.com/DylanPiercey/local-devices/issues/10)
- fix: add timeout options when exec arp ([#13](https://github.com/DylanPiercey/local-devices/pull/13))
- Fixed win32 parser for better windows support ([#9](https://github.com/DylanPiercey/local-devices/pull/9))
- validate ip address before executing command for 'find' ([#16](https://github.com/DylanPiercey/local-devices/pull/16))
## [2.0.0] - 2019-02-10
### Added
- Support for Raspberry Pi (Linux)
- Partial support for windows
- Jest test suite and tests for Linux and other platforms
- with Travis CI integration
### Changed
- fixed npm module versions in package.json
- fixed node version to v8.14.1

21
node_modules/local-devices/LICENCE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018, Dylan Piercey and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

145
node_modules/local-devices/README.md generated vendored Normal file
View File

@ -0,0 +1,145 @@
# Local Devices
[![version][version-badge]][package]
[![MIT License][license-badge]][licence]
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Build Status][build-badge]][build]
[![Coverage Status][coverage-badge]][coverage]
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
Find all devices connected to the local network using `arp -a`.
This module also pings all possible ip's in the local network to build the arp table.
## Installation
### Npm
```console
npm install local-devices
```
### Example
```javascript
// Using a transpiler
import find from 'local-devices'
// Without using a transpiler
const find = require('local-devices');
// Find all local network devices.
find().then(devices => {
devices /*
[
{ name: '?', ip: '192.168.0.10', mac: '...' },
{ name: '...', ip: '192.168.0.17', mac: '...' },
{ name: '...', ip: '192.168.0.21', mac: '...' },
{ name: '...', ip: '192.168.0.22', mac: '...' }
]
*/
})
// Find a single device by ip address.
find('192.168.0.10').then(device => {
device /*
{
name: '?',
ip: '192.168.0.10',
mac: '...'
}
*/
})
// Find all devices within 192.168.0.1 to 192.168.0.25 range
find('192.168.0.1-192.168.0.25').then(devices => {
devices /*
[
{ name: '?', ip: '192.168.0.10', mac: '...' },
{ name: '...', ip: '192.168.0.17', mac: '...' },
{ name: '...', ip: '192.168.0.21', mac: '...' },
{ name: '...', ip: '192.168.0.22', mac: '...' }
]
*/
})
// Find all devices within /24 subnet range of 192.168.0.x
find('192.168.0.0/24').then(devices => {
devices /*
[
{ name: '?', ip: '192.168.0.10', mac: '...' },
{ name: '...', ip: '192.168.0.50', mac: '...' },
{ name: '...', ip: '192.168.0.155', mac: '...' },
{ name: '...', ip: '192.168.0.211', mac: '...' }
]
*/
})
```
## Contributions
* Use `npm test` to run tests.
Please feel free to create a PR!
## Contributors
Thanks goes to these wonderful people ([emoji key][emojis]):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://twitter.com/dylan_piercey"><img src="https://avatars2.githubusercontent.com/u/4985201?v=4" width="100px;" alt="Dylan Piercey"/><br /><sub><b>Dylan Piercey</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=DylanPiercey" title="Code">💻</a> <a href="#example-DylanPiercey" title="Examples">💡</a> <a href="#review-DylanPiercey" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=DylanPiercey" title="Documentation">📖</a> <a href="#ideas-DylanPiercey" title="Ideas, Planning, & Feedback">🤔</a> <a href="#question-DylanPiercey" title="Answering Questions">💬</a></td>
<td align="center"><a href="http://twitter.com/natterstefan"><img src="https://avatars2.githubusercontent.com/u/1043668?v=4" width="100px;" alt="Stefan Natter"/><br /><sub><b>Stefan Natter</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=natterstefan" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=natterstefan" title="Tests">⚠️</a> <a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3Anatterstefan" title="Bug reports">🐛</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=natterstefan" title="Documentation">📖</a> <a href="#ideas-natterstefan" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/kounelios13"><img src="https://avatars3.githubusercontent.com/u/11466138?v=4" width="100px;" alt="kounelios13"/><br /><sub><b>kounelios13</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3Akounelios13" title="Bug reports">🐛</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=kounelios13" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/MarkusSuomi"><img src="https://avatars3.githubusercontent.com/u/5594334?v=4" width="100px;" alt="MarkusSuomi"/><br /><sub><b>MarkusSuomi</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=MarkusSuomi" title="Code">💻</a></td>
<td align="center"><a href="http://nolazybits.com"><img src="https://avatars1.githubusercontent.com/u/214998?v=4" width="100px;" alt="Xavier Martin"/><br /><sub><b>Xavier Martin</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=nolazybits" title="Code">💻</a></td>
<td align="center"><a href="https://me.howel52.com/"><img src="https://avatars0.githubusercontent.com/u/9854818?v=4" width="100px;" alt="howel52"/><br /><sub><b>howel52</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=howel52" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3Ahowel52" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/LucaSoldi"><img src="https://avatars0.githubusercontent.com/u/5584781?v=4" width="100px;" alt="LucaSoldi"/><br /><sub><b>LucaSoldi</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=LucaSoldi" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/issues?q=author%3ALucaSoldi" title="Bug reports">🐛</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/Miosame"><img src="https://avatars1.githubusercontent.com/u/8201077?v=4" width="100px;" alt="Miosame"/><br /><sub><b>Miosame</b></sub></a><br /><a href="https://github.com/DylanPiercey/local-devices/commits?author=Miosame" title="Code">💻</a> <a href="https://github.com/DylanPiercey/local-devices/commits?author=Miosame" title="Documentation">📖</a> <a href="#example-Miosame" title="Examples">💡</a></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors][all-contributors] specification.
Contributions of any kind are welcome!
### How to add Contributors
Contributors can be added with the [all-contributors cli](https://allcontributors.org/docs/en/cli/installation).
The cli is already installed and can be [used like this](https://allcontributors.org/docs/en/bot/usage):
```bash
yarn all-contributors add <username> <emoji-keys>
```
## LICENCE
[MIT](LICENCE)
[package]: https://www.npmjs.com/package/local-devices
[licence]: https://github.com/DylanPiercey/local-devices/blob/master/LICENCE
[prs]: http://makeapullrequest.com
[github-watch]: https://github.com/DylanPiercey/local-devices/watchers
[github-star]: https://github.com/DylanPiercey/local-devices/stargazers
[github-watch-badge]: https://img.shields.io/github/watchers/DylanPiercey/local-devices.svg?style=social
[github-star-badge]: https://img.shields.io/github/stars/DylanPiercey/local-devices.svg?style=social
[version-badge]: https://img.shields.io/npm/v/local-devices.svg?style=flat-square
[license-badge]: https://img.shields.io/npm/l/local-devices.svg?style=flat-square
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
[all-contributors]: https://github.com/kentcdodds/all-contributors
[build-badge]: https://travis-ci.org/DylanPiercey/local-devices.svg?branch=master
[build]: https://travis-ci.org/DylanPiercey/local-devices
[coverage-badge]: https://coveralls.io/repos/github/DylanPiercey/local-devices/badge.svg?branch=master
[coverage]: https://coveralls.io/github/DylanPiercey/local-devices?branch=master

82
node_modules/local-devices/package.json generated vendored Normal file
View File

@ -0,0 +1,82 @@
{
"name": "local-devices",
"description": "Find devices connected to the current local network.",
"version": "3.1.0",
"author": "Dylan Piercey <pierceydylan@gmail.com>",
"license": "MIT",
"main": "src/index.js",
"files": [
"src"
],
"scripts": {
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
"lint": "standard --verbose | snazzy",
"test": "jest",
"pretest": "npm run lint",
"watch-test": "jest --watch"
},
"types": "./src/index.d.ts",
"dependencies": {
"get-ip-range": "^2.1.0",
"ip": "^1.1.5",
"mz": "^2.7.0"
},
"devDependencies": {
"@types/jest": "^24.0.19",
"all-contributors-cli": "^6.9.3",
"coveralls": "^3.0.7",
"husky": "^3.0.9",
"jest": "^24.9.0",
"lint-staged": "^9.4.2",
"snazzy": "^8.0.0",
"standard": "^14.3.1"
},
"engines": {
"node": ">=10.17"
},
"homepage": "https://github.com/DylanPiercey/local-devices",
"bugs": "https://github.com/DylanPiercey/local-devices/issues",
"keywords": [
"arp",
"devices",
"ip",
"local",
"mac",
"mac-address",
"scan"
],
"repository": {
"type": "git",
"url": "https://github.com/DylanPiercey/local-devices"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm test"
}
},
"lint-staged": {
"*.js": [
"npm run lint",
"git update-index --again",
"jest --findRelatedTests"
]
},
"jest": {
"setupFiles": [
"./jest-setup.js"
]
},
"standard": {
"globals": [
"jest",
"describe",
"beforeAll",
"afterAll",
"it",
"expect"
]
}
}

16
node_modules/local-devices/src/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,16 @@
declare module "local-devices" {
function findLocalDevices(address?: any): Promise<findLocalDevices.IDevice[]>;
namespace findLocalDevices
{
interface IDevice
{
name: string;
ip: string;
mac: string;
}
}
export = findLocalDevices;
}

180
node_modules/local-devices/src/index.js generated vendored Normal file
View File

@ -0,0 +1,180 @@
var ip = require('ip')
var os = require('os')
var net = require('net')
var cp = require('mz/child_process')
var getIPRange = require('get-ip-range')
var parseLinux = require('./parser/linux')
var parseWin32 = require('./parser/win32')
var parseRow = require('./parser')
var servers
var lock = {}
const TEN_MEGA_BYTE = 1024 * 1024 * 10
const ONE_MINUTE = 60 * 1000
const options = {
maxBuffer: TEN_MEGA_BYTE,
timeout: ONE_MINUTE
}
/**
* Finds all local devices (ip and mac address) connectd to the current network.
*/
module.exports = function findLocalDevices (address) {
var key = String(address)
if (isRange(address)) {
try {
servers = getIPRange(key)
} catch (error) {
// Note: currently doesn't throw the intended error message from the package maintainer
// It will still be caught, PR here though: https://github.com/JoeScho/get-ip-range/pull/6
return error
}
} else {
servers = getServers()
}
if (!lock[key]) {
if (!address || isRange(key)) {
lock[key] = pingServers().then(arpAll).then(unlock(key))
} else {
lock[key] = pingServer(address).then(arpOne).then(unlock(key))
}
}
return lock[key]
}
function isRange (address) {
return address && new RegExp('/|-').test(address)
}
/**
* Gets the current list of possible servers in the local networks.
*/
function getServers () {
var interfaces = os.networkInterfaces()
var result = []
for (var key in interfaces) {
var addresses = interfaces[key]
for (var i = addresses.length; i--;) {
var address = addresses[i]
if (address.family === 'IPv4' && !address.internal) {
var subnet = ip.subnet(address.address, address.netmask)
var current = ip.toLong(subnet.firstAddress)
var last = ip.toLong(subnet.lastAddress) - 1
while (current++ < last) result.push(ip.fromLong(current))
}
}
}
return result
}
/**
* Sends a ping to all servers to update the arp table.
*/
function pingServers () {
return Promise.all(servers.map(pingServer))
}
/**
* Pings and individual server to update the arp table.
*/
function pingServer (address) {
return new Promise(function (resolve) {
var socket = new net.Socket()
socket.setTimeout(1000, close)
socket.connect(80, address, close)
socket.once('error', close)
function close () {
socket.destroy()
resolve(address)
}
})
}
/**
* Reads the arp table.
*/
function arpAll () {
return cp.exec('arp -a', options).then(parseAll)
}
/**
* Parses arp scan data into a useable collection.
*/
function parseAll (data) {
if (!data || !data[0]) {
return []
}
if (process.platform.includes('linux')) {
var rows = data[0].split('\n')
return rows.map(function (row) {
return parseLinux(row, servers)
}).filter(Boolean)
} else if (process.platform.includes('win32')) {
var winRows = data[0].split('\n').splice(1)
return winRows.map(function (row) {
return parseWin32(row, servers)
}).filter(Boolean)
}
return data[0]
.trim()
.split('\n')
.map(function (row) {
return parseRow(row, servers)
})
.filter(Boolean)
}
/**
* Reads the arp table for a single address.
*/
function arpOne (address) {
if (!ip.isV4Format(address) && !ip.isV6Format(address)) {
return Promise.reject(new Error('Invalid IP address provided.'))
}
return cp.exec('arp -n ' + address, options).then(parseOne)
}
/**
* Parses a single row of arp data.
*/
function parseOne (data) {
if (!data || !data[0]) {
return
}
if (process.platform.includes('linux')) {
// ignore unresolved hosts (can happen when parseOne returns only one unresolved host)
if (data[0].indexOf('no entry') >= 0) {
return
}
// remove first row (containing "headlines")
var rows = data[0].split('\n').slice(1)[0]
return parseLinux(rows, servers, true)
} else if (process.platform.includes('win32')) {
return // currently not supported
}
return parseRow(data[0], servers)
}
/**
* Clears the current promise and unlocks (will ping servers again).
*/
function unlock (key) {
return function (data) {
lock[key] = null
return data
}
}

38
node_modules/local-devices/src/parser/index.js generated vendored Normal file
View File

@ -0,0 +1,38 @@
/**
* Parses each row in the arp table into { name, ip, mac }.
*/
module.exports = function parseRow (row, servers) {
// Parse name.
var nameStart = 0
var nameEnd = row.indexOf('(') - 1
var name = row.slice(nameStart, nameEnd)
// Parse ip.
var ipStart = nameEnd + 2
var ipEnd = row.indexOf(')', ipStart)
var ipAddress = row.slice(ipStart, ipEnd)
// Only resolve external ips.
if (!~servers.indexOf(ipAddress)) {
return
}
// Parse mac
var macStart = row.indexOf(' at ', ipEnd) + 4
var macEnd = row.indexOf(' on ', macStart)
var macAddress = row.slice(macStart, macEnd)
// Ignore unresolved hosts.
if (macAddress === '(incomplete)') {
return
}
// Format for always 2 digits
macAddress = macAddress
.replace(/^.:/, '0$&')
.replace(/:.(?=:|$)/g, ':0X$&')
.replace(/X:/g, '')
return {
name: name,
ip: ipAddress,
mac: macAddress
}
}

43
node_modules/local-devices/src/parser/linux.js generated vendored Normal file
View File

@ -0,0 +1,43 @@
/**
* Parses each row in the arp table into { name, ip, mac } on linux.
*
* partially inspired by https://github.com/goliatone/arpscan/blob/master/lib/arpscanner.js
*/
module.exports = function parseLinux (row, servers, parseOne) {
var result = {}
// Ignore unresolved hosts.
if (row === '' || row.indexOf('incomplete') >= 0) {
return
}
var chunks = row.split(' ').filter(Boolean)
if (parseOne) {
result = prepareOne(chunks)
} else {
result = prepareAll(chunks)
}
// Only resolve external ips.
if (!~servers.indexOf(result.ip)) {
return
}
return result
}
function prepareOne (chunks) {
return {
name: '?', // a hostname is not provided on the raspberry pi (linux)
ip: chunks[0],
mac: chunks[2]
}
}
function prepareAll (chunks) {
return {
name: chunks[0],
ip: chunks[1].match(/\((.*)\)/)[1],
mac: chunks[3]
}
}

26
node_modules/local-devices/src/parser/win32.js generated vendored Normal file
View File

@ -0,0 +1,26 @@
/**
* Parses each row in the arp table into { name, ip, mac } on win32.
*/
module.exports = function parseRow (row, servers) {
var chunks = row.split(/\s+/g).filter(function (el) { return el.length > 1 })
// Parse name.
var ipAddress = chunks[0]
// Only resolve external ips.
if (!~servers.indexOf(ipAddress)) {
return
}
// Parse mac
var macAddress = chunks[1].replace(/-/g, ':')
// Ignore unresolved hosts.
if (macAddress === '(incomplete)') {
return
}
return {
name: '?', // unresolved
ip: ipAddress,
mac: macAddress
}
}