Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
6350088d2a | |||
10ef1d0455 | |||
f709238e50 | |||
49940635d5 | |||
ec4121cbcf | |||
ea9a2572f9 | |||
cc0f1c40a6 | |||
9da04081e4 | |||
4ae0925043 | |||
4e862e784b | |||
cf8abfd4f0 | |||
93c4488b9b | |||
39493465c6 | |||
cab696e45b | |||
67682892ae | |||
5c13987686 | |||
97841e0973 | |||
c8ccde9d84 | |||
654a4c6b54 | |||
12b8793c19 | |||
24e861e5b4 | |||
c7d2b2c031 | |||
f08713bb45 | |||
ad0fa8c65a | |||
88a9bfc20d | |||
0248d6f253 | |||
8d1b302e70 | |||
34bee225d5 | |||
ccece078a2 | |||
a04151e537 | |||
d71346e763 | |||
817894b6ce | |||
bba219ddef | |||
9af53a5b58 | |||
4fcdeb8c3d | |||
5c7d2de902 | |||
f105cdc806 | |||
8f71c68d8c | |||
beb6680856 | |||
311852efe8 | |||
d3a507c3ff | |||
05bc8fb72c | |||
df861590c8 | |||
2ce69f4a8e | |||
7625866ca9 |
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,5 +1,20 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@ -18,102 +18,114 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -121,5 +133,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.13.5
|
||||
ignore: {}
|
||||
patch: {}
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"npmts"
|
||||
],
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
|
13231
package-lock.json
generated
13231
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@ -1,25 +1,45 @@
|
||||
{
|
||||
"name": "@pushrocks/smartnetwork",
|
||||
"version": "1.1.3",
|
||||
"version": "2.0.3",
|
||||
"private": false,
|
||||
"description": "network diagnostics",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tsrun test/test.ts)",
|
||||
"build": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsrun": "^1.2.5",
|
||||
"@pushrocks/tapbundle": "^3.0.9"
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tstest": "^1.0.52",
|
||||
"@pushrocks/tapbundle": "^3.2.14",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartstring": "^3.0.10",
|
||||
"@types/portscanner": "^2.1.0",
|
||||
"portscanner": "^2.2.0",
|
||||
"speedtest-net": "^1.5.1"
|
||||
}
|
||||
"@pushrocks/smartpromise": "^3.1.3",
|
||||
"@pushrocks/smartstring": "^3.0.24",
|
||||
"@types/default-gateway": "^3.0.1",
|
||||
"isopen": "^1.3.0",
|
||||
"public-ip": "^4.0.3",
|
||||
"speedtest-net": "^2.1.1",
|
||||
"systeminformation": "^5.6.12"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
47
readme.md
47
readme.md
@ -8,25 +8,50 @@ network diagnostics
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnetwork/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartnetwork/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartnetwork/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartnetwork)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartnetwork)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
import * as smartnetwork from 'smartnetwork';
|
||||
testSmartNetwork = new smartnetwork.SmartNetwork();
|
||||
testSmartNetwork.getSpeed
|
||||
const testSmartNetwork = new smartnetwork.SmartNetwork();
|
||||
const run = async () => {
|
||||
// measure average speed over a period of 5 seconds
|
||||
// the structure of speedResult is self explanatory using TypeScript (or the linked TypeDoc above)
|
||||
const speedResult = testSmartNetwork.getSpeed(5000);
|
||||
|
||||
//
|
||||
const isLocalPortAvailable: boolean = await testSmartNetwork.isLocalPortAvailable(1234);
|
||||
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable(
|
||||
'google.com:80'
|
||||
);
|
||||
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable(
|
||||
'google.com',
|
||||
80
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
28
test/test.ts
28
test/test.ts
@ -9,18 +9,34 @@ tap.test('should create a valid instance of SmartNetwork', async () => {
|
||||
});
|
||||
|
||||
tap.test('should perform a speedtest', async () => {
|
||||
let result = await testSmartNetwork.getSpeed();
|
||||
console.log(`Download speed for this instance is ${result.speeds.download}`);
|
||||
console.log(`Upload speed for this instance is ${result.speeds.upload}`);
|
||||
const result = await testSmartNetwork.getSpeed();
|
||||
console.log(`Download speed for this instance is ${result.download.bandwidth}`);
|
||||
console.log(`Upload speed for this instance is ${result.download.bandwidth}`);
|
||||
});
|
||||
|
||||
tap.test('should determine wether a port is free', async () => {
|
||||
await expect(testSmartNetwork.isLocalPortAvailable(8080)).to.eventually.be.true;
|
||||
await expect(testSmartNetwork.isLocalPortUnused(8080)).to.eventually.be.true;
|
||||
});
|
||||
|
||||
tap.test('should scan a port', async () => {
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('google.com:80')).to.eventually.be.true;
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('67.207.79.63:12346')).to.eventually.be.false;
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:443')).to.eventually.be.true;
|
||||
await expect(testSmartNetwork.isRemotePortAvailable('lossless.com', 443)).to.be.eventually.true;
|
||||
// await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).to.eventually.be.false;
|
||||
});
|
||||
|
||||
tap.test('should get gateways', async () => {
|
||||
const gatewayResult = await testSmartNetwork.getGateways();
|
||||
console.log(gatewayResult);
|
||||
});
|
||||
|
||||
tap.test('should get the default gateway', async () => {
|
||||
const gatewayResult = await testSmartNetwork.getDefaultGateway();
|
||||
console.log(gatewayResult);
|
||||
});
|
||||
|
||||
tap.test('should get public ips', async () => {
|
||||
const ips = await testSmartNetwork.getPublicIps();
|
||||
console.log(ips);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,34 +1,31 @@
|
||||
import * as plugins from './smartnetwork.plugins';
|
||||
|
||||
export class ISpeedtestData {
|
||||
speeds: {
|
||||
download: number;
|
||||
upload: number;
|
||||
originalDownload: number;
|
||||
originalUpload: number;
|
||||
};
|
||||
client: {
|
||||
ip: string;
|
||||
lat: number;
|
||||
lon: number;
|
||||
isp: string;
|
||||
isprating: string;
|
||||
rating: number;
|
||||
ispdlavg: number;
|
||||
ispulavg: number;
|
||||
export interface ISpeedtestData {
|
||||
timestamp: Date;
|
||||
ping: { jitter: number; latency: number };
|
||||
download: { bandwidth: number; bytes: number; elapsed: number };
|
||||
upload: { bandwidth: number; bytes: number; elapsed: number };
|
||||
packetLoss: number;
|
||||
isp: string;
|
||||
interface: {
|
||||
internalIp: string;
|
||||
name: string;
|
||||
macAddr: string;
|
||||
isVpn: false;
|
||||
externalIp: string;
|
||||
};
|
||||
server: {
|
||||
host: string;
|
||||
lat: number;
|
||||
lon: number;
|
||||
id: number;
|
||||
name: string;
|
||||
location: string;
|
||||
country: string;
|
||||
cc: string;
|
||||
sponsor: string;
|
||||
distance: number;
|
||||
distanceMi: number;
|
||||
ping: number;
|
||||
host: string;
|
||||
port: number;
|
||||
ip: string;
|
||||
};
|
||||
result: {
|
||||
id: string;
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
|
||||
@ -36,16 +33,13 @@ export class ISpeedtestData {
|
||||
* SmartNetwork simplifies actions within the network
|
||||
*/
|
||||
export class SmartNetwork {
|
||||
async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
|
||||
let done = plugins.smartpromise.defer<ISpeedtestData>();
|
||||
const test = plugins.speedtestNet({ maxTime: measurementTime });
|
||||
test.on('data', data => {
|
||||
done.resolve(data);
|
||||
});
|
||||
test.on('error', err => {
|
||||
done.reject(err);
|
||||
});
|
||||
return await done.promise;
|
||||
/**
|
||||
* get network speed
|
||||
* @param measurementTime
|
||||
*/
|
||||
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
|
||||
const test = await plugins.speedtestNet({ maxTime: measurementTime, acceptGdpr: true });
|
||||
return test;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,21 +47,21 @@ export class SmartNetwork {
|
||||
* note: false also resolves with false as argument
|
||||
* @param port
|
||||
*/
|
||||
async isLocalPortAvailable(port: number): Promise<boolean> {
|
||||
public async isLocalPortUnused(port: number): Promise<boolean> {
|
||||
const doneIpV4 = plugins.smartpromise.defer<boolean>();
|
||||
const doneIpV6 = plugins.smartpromise.defer<boolean>();
|
||||
const net = await import('net'); // creates only one instance of net ;) even on multiple calls
|
||||
|
||||
// test IPv4 space
|
||||
const ipv4Test = net.createServer();
|
||||
ipv4Test.once('error', function(err: any) {
|
||||
ipv4Test.once('error', (err: any) => {
|
||||
if (err.code !== 'EADDRINUSE') {
|
||||
doneIpV4.resolve(false);
|
||||
return;
|
||||
}
|
||||
doneIpV4.resolve(false);
|
||||
});
|
||||
ipv4Test.once('listening', function() {
|
||||
ipv4Test.once('listening', () => {
|
||||
ipv4Test.once('close', () => {
|
||||
doneIpV4.resolve(true);
|
||||
});
|
||||
@ -78,21 +72,21 @@ export class SmartNetwork {
|
||||
await doneIpV4.promise;
|
||||
|
||||
// test IPv6 space
|
||||
const test_ipv6 = net.createServer();
|
||||
test_ipv6.once('error', function(err: any) {
|
||||
const ipv6Test = net.createServer();
|
||||
ipv6Test.once('error', function (err: any) {
|
||||
if (err.code !== 'EADDRINUSE') {
|
||||
doneIpV6.resolve(false);
|
||||
return;
|
||||
}
|
||||
doneIpV6.resolve(false);
|
||||
});
|
||||
test_ipv6.once('listening', function() {
|
||||
test_ipv6.once('close', () => {
|
||||
ipv6Test.once('listening', () => {
|
||||
ipv6Test.once('close', () => {
|
||||
doneIpV6.resolve(true);
|
||||
});
|
||||
test_ipv6.close();
|
||||
ipv6Test.close();
|
||||
});
|
||||
test_ipv6.listen(port, '::');
|
||||
ipv6Test.listen(port, '::');
|
||||
|
||||
// lets wait for the result
|
||||
const resultIpV4 = await doneIpV4.promise;
|
||||
@ -110,17 +104,46 @@ export class SmartNetwork {
|
||||
const domainPart = domainArg.split(':')[0];
|
||||
const port = portArg ? portArg : parseInt(domainArg.split(':')[1], 10);
|
||||
|
||||
plugins.portscanner.checkPortStatus(port, domainPart, (err, status ) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
if (status === 'open') {
|
||||
plugins.isopen(domainPart, port, (response) => {
|
||||
console.log(response);
|
||||
if (response[port.toString()].isOpen) {
|
||||
done.resolve(true);
|
||||
} else {
|
||||
done.resolve(false)
|
||||
done.resolve(false);
|
||||
}
|
||||
})
|
||||
});
|
||||
const result = await done.promise;
|
||||
return result;
|
||||
}
|
||||
|
||||
public async getGateways() {
|
||||
const result = plugins.os.networkInterfaces();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async getDefaultGateway(): Promise<{
|
||||
ipv4: plugins.os.NetworkInterfaceInfo;
|
||||
ipv6: plugins.os.NetworkInterfaceInfo;
|
||||
}> {
|
||||
const defaultGatewayName = await plugins.systeminformation.networkInterfaceDefault();
|
||||
if (!defaultGatewayName) {
|
||||
console.log('Cannot determine default gateway');
|
||||
return null;
|
||||
}
|
||||
const gateways = await this.getGateways();
|
||||
const defaultGateway = gateways[defaultGatewayName];
|
||||
return {
|
||||
ipv4: defaultGateway[0],
|
||||
ipv6: defaultGateway[1],
|
||||
};
|
||||
}
|
||||
|
||||
public async getPublicIps() {
|
||||
return {
|
||||
v4: await plugins.publicIp.v4({
|
||||
timeout: 1000,
|
||||
onlyHttps: true,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
// native scope
|
||||
import * as os from 'os';
|
||||
|
||||
export { os };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
@ -7,7 +10,9 @@ import * as smartstring from '@pushrocks/smartstring';
|
||||
export { smartpromise, smartstring };
|
||||
|
||||
// @third party scope
|
||||
let speedtestNet = require('speedtest-net');
|
||||
import * as portscanner from 'portscanner';
|
||||
import isopen from 'isopen';
|
||||
import publicIp from 'public-ip';
|
||||
import speedtestNet from 'speedtest-net';
|
||||
import * as systeminformation from 'systeminformation';
|
||||
|
||||
export { speedtestNet, portscanner };
|
||||
export { isopen, publicIp, speedtestNet, systeminformation };
|
||||
|
Reference in New Issue
Block a user