Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
54bb9549a1 | |||
95c3314400 | |||
695d047200 | |||
c308589d28 |
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -36,6 +39,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
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",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartnetwork",
|
"gitrepo": "smartnetwork",
|
||||||
"shortDescription": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"npmPackagename": "@pushrocks/smartnetwork",
|
"npmPackagename": "@pushrocks/smartnetwork",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
53
package-lock.json
generated
53
package-lock.json
generated
@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "2.0.11",
|
"version": "2.0.13",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "2.0.11",
|
"version": "2.0.13",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.1.6",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@types/default-gateway": "^3.0.1",
|
"@types/default-gateway": "^3.0.1",
|
||||||
|
"icmp": "^2.0.1",
|
||||||
"isopen": "^1.3.0",
|
"isopen": "^1.3.0",
|
||||||
"public-ip": "^4.0.4",
|
"public-ip": "^4.0.4",
|
||||||
"systeminformation": "^5.11.3"
|
"systeminformation": "^5.11.3"
|
||||||
@ -8443,6 +8444,15 @@
|
|||||||
"ms": "^2.0.0"
|
"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": {
|
"node_modules/iconv-lite": {
|
||||||
"version": "0.4.24",
|
"version": "0.4.24",
|
||||||
"resolved": "https://verdaccio.lossless.one/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
"resolved": "https://verdaccio.lossless.one/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||||
@ -12449,6 +12459,22 @@
|
|||||||
"node": ">= 0.8"
|
"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": {
|
"node_modules/readable-stream": {
|
||||||
"version": "2.3.7",
|
"version": "2.3.7",
|
||||||
"resolved": "https://verdaccio.lossless.one/readable-stream/-/readable-stream-2.3.7.tgz",
|
"resolved": "https://verdaccio.lossless.one/readable-stream/-/readable-stream-2.3.7.tgz",
|
||||||
@ -22139,6 +22165,14 @@
|
|||||||
"ms": "^2.0.0"
|
"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": {
|
"iconv-lite": {
|
||||||
"version": "0.4.24",
|
"version": "0.4.24",
|
||||||
"resolved": "https://verdaccio.lossless.one/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
"resolved": "https://verdaccio.lossless.one/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||||
@ -25112,6 +25146,21 @@
|
|||||||
"unpipe": "1.0.0"
|
"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": {
|
"readable-stream": {
|
||||||
"version": "2.3.7",
|
"version": "2.3.7",
|
||||||
"resolved": "https://verdaccio.lossless.one/readable-stream/-/readable-stream-2.3.7.tgz",
|
"resolved": "https://verdaccio.lossless.one/readable-stream/-/readable-stream-2.3.7.tgz",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "2.0.11",
|
"version": "2.0.13",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"@pushrocks/smartpromise": "^3.1.6",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
"@pushrocks/smartstring": "^3.0.24",
|
||||||
"@types/default-gateway": "^3.0.1",
|
"@types/default-gateway": "^3.0.1",
|
||||||
|
"icmp": "^2.0.1",
|
||||||
"isopen": "^1.3.0",
|
"isopen": "^1.3.0",
|
||||||
"public-ip": "^4.0.4",
|
"public-ip": "^4.0.4",
|
||||||
"systeminformation": "^5.11.3"
|
"systeminformation": "^5.11.3"
|
||||||
|
16
test/test.ping.ts
Normal file
16
test/test.ping.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -106,7 +106,7 @@ export class CloudflareSpeed {
|
|||||||
public async fetchServerLocations(): Promise<{ [key: string]: string }> {
|
public async fetchServerLocations(): Promise<{ [key: string]: string }> {
|
||||||
const res = JSON.parse(await this.get('speed.cloudflare.com', '/locations'));
|
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
|
// Bypass prettier "no-assign-param" rules
|
||||||
const data1 = data;
|
const data1 = data;
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ export class CloudflareSpeed {
|
|||||||
public async request(options: plugins.https.RequestOptions, data = ''): Promise<number[]> {
|
public async request(options: plugins.https.RequestOptions, data = ''): Promise<number[]> {
|
||||||
let started: number;
|
let started: number;
|
||||||
let dnsLookup: number;
|
let dnsLookup: number;
|
||||||
let tcpHandshake : number;
|
let tcpHandshake: number;
|
||||||
let sslHandshake: number;
|
let sslHandshake: number;
|
||||||
let ttfb: number;
|
let ttfb: number;
|
||||||
let ended: number;
|
let ended: number;
|
||||||
|
@ -16,6 +16,19 @@ export class SmartNetwork {
|
|||||||
return test;
|
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
|
* returns a promise with a boolean answer
|
||||||
* note: false also resolves with false as argument
|
* note: false also resolves with false as argument
|
||||||
|
@ -13,7 +13,8 @@ export { smartpromise, smartstring };
|
|||||||
|
|
||||||
// @third party scope
|
// @third party scope
|
||||||
const isopen = require('isopen');
|
const isopen = require('isopen');
|
||||||
import publicIp from 'public-ip';
|
const icmp = require('icmp');
|
||||||
|
import * as publicIp from 'public-ip';
|
||||||
import * as systeminformation from 'systeminformation';
|
import * as systeminformation from 'systeminformation';
|
||||||
|
|
||||||
export { isopen, publicIp, systeminformation };
|
export { isopen, icmp, publicIp, systeminformation };
|
||||||
|
Reference in New Issue
Block a user