# @push.rocks/smartnetwork network diagnostics ## Install To install `@push.rocks/smartnetwork`, run the following command in your terminal: ```bash 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: ```typescript import { SmartNetwork } from '@push.rocks/smartnetwork'; ``` Then, create an instance of `SmartNetwork`: ```typescript 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. ```typescript 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. ```typescript 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. ```typescript 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. ```typescript 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. ```typescript 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: ```typescript 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. ## License and Legal Information 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](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.