Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
b52bb4b474 | |||
42f5d66fc4 | |||
54bb9549a1 | |||
95c3314400 | |||
695d047200 | |||
c308589d28 |
@ -12,6 +12,9 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
@ -36,6 +39,7 @@ auditProductionDependencies:
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"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"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartnetwork",
|
||||
"shortDescription": "network diagnostics",
|
||||
"description": "network diagnostics",
|
||||
"npmPackagename": "@pushrocks/smartnetwork",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
53
package-lock.json
generated
53
package-lock.json
generated
@ -1,17 +1,18 @@
|
||||
{
|
||||
"name": "@pushrocks/smartnetwork",
|
||||
"version": "2.0.11",
|
||||
"version": "2.0.14",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@pushrocks/smartnetwork",
|
||||
"version": "2.0.11",
|
||||
"version": "2.0.14",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^3.1.6",
|
||||
"@pushrocks/smartstring": "^3.0.24",
|
||||
"@types/default-gateway": "^3.0.1",
|
||||
"icmp": "^2.0.1",
|
||||
"isopen": "^1.3.0",
|
||||
"public-ip": "^4.0.4",
|
||||
"systeminformation": "^5.11.3"
|
||||
@ -8443,6 +8444,15 @@
|
||||
"ms": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/icmp": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://verdaccio.lossless.one/icmp/-/icmp-2.0.1.tgz",
|
||||
"integrity": "sha512-M7r2J6pjZOwZFSjsFNvYlWvtpVbCckwCd2EQSHc4Mzscwp9X7DUpnPcQiVceKI9YQ42INb53cMmgIzaRs87Jmg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"raw-socket": "^1.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://verdaccio.lossless.one/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
@ -12449,6 +12459,22 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-socket": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://verdaccio.lossless.one/raw-socket/-/raw-socket-1.7.0.tgz",
|
||||
"integrity": "sha512-mXqWihgwaFNmV5le0dWk5o+03M3A2zBIkC9BNaE6R0CJN9eYot++j2FIqgNSDq6/Vmu32PPI155SiiWNV2yyFQ==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "2.14.*"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-socket/node_modules/nan": {
|
||||
"version": "2.14.2",
|
||||
"resolved": "https://verdaccio.lossless.one/nan/-/nan-2.14.2.tgz",
|
||||
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/readable-stream": {
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://verdaccio.lossless.one/readable-stream/-/readable-stream-2.3.7.tgz",
|
||||
@ -22139,6 +22165,14 @@
|
||||
"ms": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"icmp": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://verdaccio.lossless.one/icmp/-/icmp-2.0.1.tgz",
|
||||
"integrity": "sha512-M7r2J6pjZOwZFSjsFNvYlWvtpVbCckwCd2EQSHc4Mzscwp9X7DUpnPcQiVceKI9YQ42INb53cMmgIzaRs87Jmg==",
|
||||
"requires": {
|
||||
"raw-socket": "^1.7.0"
|
||||
}
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://verdaccio.lossless.one/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
@ -25112,6 +25146,21 @@
|
||||
"unpipe": "1.0.0"
|
||||
}
|
||||
},
|
||||
"raw-socket": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://verdaccio.lossless.one/raw-socket/-/raw-socket-1.7.0.tgz",
|
||||
"integrity": "sha512-mXqWihgwaFNmV5le0dWk5o+03M3A2zBIkC9BNaE6R0CJN9eYot++j2FIqgNSDq6/Vmu32PPI155SiiWNV2yyFQ==",
|
||||
"requires": {
|
||||
"nan": "2.14.*"
|
||||
},
|
||||
"dependencies": {
|
||||
"nan": {
|
||||
"version": "2.14.2",
|
||||
"resolved": "https://verdaccio.lossless.one/nan/-/nan-2.14.2.tgz",
|
||||
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://verdaccio.lossless.one/readable-stream/-/readable-stream-2.3.7.tgz",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartnetwork",
|
||||
"version": "2.0.11",
|
||||
"version": "2.0.14",
|
||||
"private": false,
|
||||
"description": "network diagnostics",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -22,6 +22,7 @@
|
||||
"@pushrocks/smartpromise": "^3.1.6",
|
||||
"@pushrocks/smartstring": "^3.0.24",
|
||||
"@types/default-gateway": "^3.0.1",
|
||||
"icmp": "^2.0.1",
|
||||
"isopen": "^1.3.0",
|
||||
"public-ip": "^4.0.4",
|
||||
"systeminformation": "^5.11.3"
|
||||
|
18
test/test.ping.ts
Normal file
18
test/test.ping.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartnetwork from '../ts';
|
||||
|
||||
let testSmartnetwork: smartnetwork.SmartNetwork;
|
||||
|
||||
tap.test('should create a vlid instance of SmartNetwork', async () => {
|
||||
testSmartnetwork = new smartnetwork.SmartNetwork();
|
||||
expect(testSmartnetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
||||
});
|
||||
|
||||
tap.test('should send a ping to Google', async () => {
|
||||
expectAsync(testSmartnetwork.ping('https://lossless.com')).toBeTrue();
|
||||
expectAsync(testSmartnetwork.ping('https://notthere.lossless.com')).toBeTrue();
|
||||
expectAsync(testSmartnetwork.ping('192.168.186.999')).toBeFalse();
|
||||
});
|
||||
|
||||
tap.start();
|
@ -106,7 +106,7 @@ export class CloudflareSpeed {
|
||||
public async fetchServerLocations(): Promise<{ [key: string]: string }> {
|
||||
const res = JSON.parse(await this.get('speed.cloudflare.com', '/locations'));
|
||||
|
||||
return res.reduce((data: any, optionsArg: { iata: string, city: string}) => {
|
||||
return res.reduce((data: any, optionsArg: { iata: string; city: string }) => {
|
||||
// Bypass prettier "no-assign-param" rules
|
||||
const data1 = data;
|
||||
|
||||
@ -172,7 +172,7 @@ export class CloudflareSpeed {
|
||||
public async request(options: plugins.https.RequestOptions, data = ''): Promise<number[]> {
|
||||
let started: number;
|
||||
let dnsLookup: number;
|
||||
let tcpHandshake : number;
|
||||
let tcpHandshake: number;
|
||||
let sslHandshake: number;
|
||||
let ttfb: number;
|
||||
let ended: number;
|
||||
|
@ -16,6 +16,19 @@ export class SmartNetwork {
|
||||
return test;
|
||||
}
|
||||
|
||||
public async ping(hostArg: string, timeoutArg: number = 500): Promise<boolean> {
|
||||
if (process.getuid() !== 0) {
|
||||
console.log('icmp not allowed for nonroot!');
|
||||
return;
|
||||
}
|
||||
const result = await plugins.icmp.ping(hostArg, timeoutArg).catch();
|
||||
if (result) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a promise with a boolean answer
|
||||
* note: false also resolves with false as argument
|
||||
|
@ -13,7 +13,8 @@ export { smartpromise, smartstring };
|
||||
|
||||
// @third party scope
|
||||
const isopen = require('isopen');
|
||||
import publicIp from 'public-ip';
|
||||
const icmp = require('icmp');
|
||||
import * as publicIp from 'public-ip';
|
||||
import * as systeminformation from 'systeminformation';
|
||||
|
||||
export { isopen, publicIp, systeminformation };
|
||||
export { isopen, icmp, publicIp, systeminformation };
|
||||
|
Reference in New Issue
Block a user