A toolkit for network diagnostics including speed tests, port availability checks, and more.
Go to file
2024-05-29 14:14:57 +02:00
.vscode fix(core): update 2022-02-17 00:18:23 +01:00
test fix(core): update 2022-10-21 17:13:06 +02:00
ts fix(core): update 2022-10-22 17:39:29 +02:00
.gitignore fix(core): update 2020-08-12 16:30:17 +00:00
.gitlab-ci.yml fix(core): update 2022-02-17 00:18:23 +01:00
license fix(core): update 2021-04-28 13:41:55 +00:00
npmextra.json update tsconfig 2024-04-14 18:02:08 +02:00
package.json update description 2024-05-29 14:14:57 +02:00
pnpm-lock.yaml switch to new org scheme 2023-07-11 01:15:20 +02:00
readme.hints.md update tsconfig 2024-04-14 18:02:08 +02:00
readme.md update tsconfig 2024-04-14 18:02:08 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:36:49 +02:00

@push.rocks/smartnetwork

network diagnostics

Install

To install @push.rocks/smartnetwork, run the following command in your terminal:

npm install @push.rocks/smartnetwork --save

This command will download @push.rocks/smartnetwork and add it to your project's package.json file.

Usage

In this section, we will dive deep into the capabilities of the @push.rocks/smartnetwork package, exploring its various features through TypeScript examples. The package is designed to simplify network diagnostics tasks, including speed tests, port availability checks, ping operations, and more.

Basic Setup

First, import the package into your project:

import { SmartNetwork } from '@push.rocks/smartnetwork';

Then, create an instance of SmartNetwork:

const myNetwork = new SmartNetwork();

Performing a Speed Test

You can measure the network speed using the getSpeed method. This feature leverages Cloudflare's speed test capabilities to assess your internet connection's download and upload speeds.

const speedTest = async () => {
  const speedResult = await myNetwork.getSpeed();
  console.log(`Download speed: ${speedResult.downloadSpeed} Mbps`);
  console.log(`Upload speed: ${speedResult.uploadSpeed} Mbps`);
  console.log(`Latency: ${speedResult.averageTime} ms`);
};

speedTest();

Checking Port Availability Locally

The isLocalPortUnused method allows you to check if a specific port on your local machine is available for use.

const checkLocalPort = async (port: number) => {
  const isUnused = await myNetwork.isLocalPortUnused(port);
  if (isUnused) {
    console.log(`Port ${port} is available.`);
  } else {
    console.log(`Port ${port} is in use.`);
  }
};

checkLocalPort(8080);  // Example port number

Checking Remote Port Availability

To verify if a certain port is available on a remote server, use isRemotePortAvailable. This can help determine if a service is up and reachable.

const checkRemotePort = async (hostname: string, port: number) => {
  const isAvailable = await myNetwork.isRemotePortAvailable(hostname, port);
  if (isAvailable) {
    console.log(`Port ${port} on ${hostname} is available.`);
  } else {
    console.log(`Port ${port} on ${hostname} is not available.`);
  }
};

checkRemotePort('example.com', 443);  // Checking HTTPS port on example.com

Using Ping

The ping method allows you to send ICMP packets to a host to measure round-trip time and determine if the host is reachable.

const pingHost = async (hostname: string) => {
  const pingResult = await myNetwork.ping(hostname);
  if (pingResult.alive) {
    console.log(`${hostname} is reachable. RTT: ${pingResult.time} ms`);
  } else {
    console.log(`${hostname} is not reachable.`);
  }
};

pingHost('google.com');

Getting Network Gateways

You can also retrieve information about your network gateways, including the default gateway used by your machine.

const showGateways = async () => {
  const gateways = await myNetwork.getGateways();
  console.log(gateways);

  const defaultGateway = await myNetwork.getDefaultGateway();
  console.log(`Default Gateway: `, defaultGateway);
};

showGateways();

Discovering Public IP Addresses

To find out your public IPv4 and IPv6 addresses, the following method can be used:

const showPublicIps = async () => {
  const publicIps = await myNetwork.getPublicIps();
  console.log(`Public IPv4: ${publicIps.v4}`);
  console.log(`Public IPv6: ${publicIps.v6}`);
};

showPublicIps();

The @push.rocks/smartnetwork package provides an easy-to-use, comprehensive suite of tools for network diagnostics and monitoring, encapsulating complex network operations into simple asynchronous methods. By leveraging TypeScript, developers can benefit from type checking, ensuring that they can work with clear structures and expectations.

These examples offer a glimpse into the module's utility in real-world scenarios, demonstrating its versatility in handling common network tasks. Whether you're developing a network-sensitive application, diagnosing connectivity issues, or simply curious about your network performance, @push.rocks/smartnetwork equips you with the tools you need.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.