2025-09-12 13:30:09 +00:00
# @push.rocks/smartnetwork 🌐
2025-04-28 12:58:01 +00:00
2026-03-26 15:44:05 +00:00
Comprehensive network diagnostics and IP intelligence for Node.js — speed tests, port scanning, ICMP ping, traceroute, DNS, RDAP, ASN lookups, and geolocation in a single, promise-based toolkit.
2019-04-16 10:21:11 +02:00
2026-03-26 15:44:05 +00:00
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/ ](https://community.foss.global/ ). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/ ](https://code.foss.global/ ) account to submit Pull Requests directly.
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
## 🚀 Install
2024-04-14 18:02:08 +02:00
```bash
2025-09-12 13:30:09 +00:00
pnpm install @push .rocks/smartnetwork --save
2024-04-14 18:02:08 +02:00
```
2025-09-12 13:30:09 +00:00
## 🎯 Overview
2019-04-16 10:21:11 +02:00
2026-03-26 15:44:05 +00:00
**@push .rocks/smartnetwork** is your Swiss Army knife for network diagnostics in Node.js. Whether you're building monitoring dashboards, investigating IP ownership, or debugging connectivity — this library has you covered with a clean, async API and zero-config setup.
Under the hood, system-level operations (ICMP ping, traceroute, raw-socket port checks, gateway detection) are powered by a bundled **Rust binary ** for maximum performance and cross-platform reliability. Everything else — speed tests, DNS, public IP discovery, IP intelligence, HTTP health checks — runs in pure TypeScript.
2025-09-12 13:30:09 +00:00
### ✨ Key Features
2026-03-26 15:44:05 +00:00
| Category | Capabilities |
|----------|-------------|
| 🏎️ **Speed Testing ** | Download/upload benchmarks via Cloudflare's global infrastructure |
| 🔌 **Port Management ** | Local/remote port checks, find free ports (sequential or random), exclusion lists |
| 📡 **Connectivity ** | ICMP ping with stats, hop-by-hop traceroute, HTTP/HTTPS health checks |
| 🌍 **DNS ** | A, AAAA, MX resolution with system-first + DoH fallback strategy |
| 🔍 **IP Intelligence ** | ASN, organization, geolocation, RDAP registration — all from free public sources |
| 🖥️ **Network Discovery ** | Interfaces, default gateway, public IPv4/IPv6 |
| ⚡ **Caching ** | Built-in TTL cache for expensive lookups |
| 🔧 **Extensible ** | Plugin architecture for custom functionality |
| 📝 **TypeScript ** | Full type definitions, ESM-native |
2025-09-12 13:30:09 +00:00
## 💻 Usage
2024-04-14 18:02:08 +02:00
### Basic Setup
```typescript
import { SmartNetwork } from '@push .rocks/smartnetwork';
2025-09-12 13:30:09 +00:00
const network = new SmartNetwork();
2024-04-14 18:02:08 +02:00
2026-03-26 15:24:43 +00:00
// Start the Rust bridge (auto-started on first use, but explicit start is recommended)
await network.start();
// ... use the network instance ...
2026-03-26 15:44:05 +00:00
// Clean up when done
2026-03-26 15:24:43 +00:00
await network.stop();
2025-07-31 22:04:20 +00:00
```
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
Enable caching for repeated lookups:
2024-04-14 18:02:08 +02:00
```typescript
2026-03-26 15:44:05 +00:00
const network = new SmartNetwork({ cacheTtl: 60000 }); // 60s TTL
2024-04-14 18:02:08 +02:00
```
2026-03-26 15:44:05 +00:00
---
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
### 🕵️ IP Intelligence
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
Get ASN, organization, geolocation, and RDAP registration data for any IPv4 address. Combines three free public data sources in parallel:
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
- **RDAP** — direct queries to RIRs (RIPE, ARIN, APNIC, LACNIC, AFRINIC) for authoritative registration data
- **Team Cymru DNS** — fast ASN resolution via DNS TXT records
- **MaxMind GeoLite2** — in-memory MMDB databases (auto-downloaded from CDN, periodically refreshed)
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
```typescript
const intel = await network.getIpIntelligence('8.8.8.8');
console.log(intel);
// {
// asn: 15169,
// asnOrg: 'Google LLC',
// registrantOrg: 'Google LLC',
// registrantCountry: 'United States',
// networkRange: '8.8.8.0/24',
// abuseContact: null,
// country: null,
// countryCode: 'US',
// city: null,
// latitude: 37.751,
// longitude: -97.822,
// accuracyRadius: null,
// timezone: 'America/Chicago'
// }
2025-07-31 22:04:20 +00:00
```
2026-03-26 15:44:05 +00:00
Works great for your own IP too:
2025-07-31 22:04:20 +00:00
```typescript
2026-03-26 15:44:05 +00:00
const publicIps = await network.getPublicIps();
if (publicIps.v4) {
const myIntel = await network.getIpIntelligence(publicIps.v4);
console.log(`You're on AS${myIntel.asn} (${myIntel.asnOrg}) in ${myIntel.city}, ${myIntel.countryCode}` );
}
2024-04-14 18:02:08 +02:00
```
2026-03-26 15:44:05 +00:00
The `IIpIntelligenceResult` interface:
2024-04-14 18:02:08 +02:00
```typescript
2026-03-26 15:44:05 +00:00
interface IIpIntelligenceResult {
// ASN (Team Cymru primary, MaxMind fallback)
asn: number | null;
asnOrg: string | null;
// Registration (RDAP)
registrantOrg: string | null;
registrantCountry: string | null;
networkRange: string | null; // CIDR or range
abuseContact: string | null; // abuse email from RDAP
// Geolocation (MaxMind GeoLite2)
country: string | null;
countryCode: string | null; // ISO 3166-1 alpha-2
city: string | null;
latitude: number | null;
longitude: number | null;
accuracyRadius: number | null; // km
timezone: string | null; // IANA timezone
2025-04-28 19:27:13 +00:00
}
2024-04-14 18:02:08 +02:00
```
2026-03-26 15:44:05 +00:00
> 💡 The GeoLite2 databases are fetched into memory from jsDelivr CDN on first use (~32 MB total). They auto-refresh in the background every 7 days (configurable via `IpIntelligence` options). No disk I/O, no API keys, no rate limits.
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
---
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
### 🏎️ Speed Testing
Measure network performance via Cloudflare's global infrastructure:
2024-04-14 18:02:08 +02:00
```typescript
2026-03-26 15:44:05 +00:00
const result = await network.getSpeed();
console.log(`⬇️ Download: ${result.downloadSpeed} Mbps` );
console.log(`⬆️ Upload: ${result.uploadSpeed} Mbps` );
// Advanced: parallel streams + fixed duration
const advanced = await network.getSpeed({
parallelStreams: 3,
duration: 5,
2025-07-31 22:04:20 +00:00
});
```
2026-03-26 15:44:05 +00:00
---
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
### 🔌 Port Management
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
#### Check Local Port Availability
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
Checks both IPv4 and IPv6:
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
```typescript
const isUnused = await network.isLocalPortUnused(8080);
console.log(isUnused ? '✅ Port 8080 is free' : '❌ Port 8080 is in use');
```
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
#### Find Free Port in Range
2024-04-14 18:02:08 +02:00
2019-04-16 10:21:11 +02:00
```typescript
2026-03-26 15:44:05 +00:00
// First available
const port = await network.findFreePort(3000, 3100);
2019-04-17 20:05:07 +02:00
2026-03-26 15:44:05 +00:00
// Random pick (avoids clustering)
const randomPort = await network.findFreePort(3000, 3100, { randomize: true });
2021-04-28 13:41:55 +00:00
2026-03-26 15:44:05 +00:00
// With exclusions
const port2 = await network.findFreePort(3000, 3100, {
randomize: true,
exclude: [3000, 3001, 3005],
2025-07-31 22:04:20 +00:00
});
2024-04-14 18:02:08 +02:00
```
2021-04-28 13:41:55 +00:00
2026-03-26 15:44:05 +00:00
#### Check Remote Port
2024-04-14 18:02:08 +02:00
```typescript
2026-03-26 15:44:05 +00:00
// Simple
const isOpen = await network.isRemotePortAvailable('example.com', 443);
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
// With retries and timeout
const isOpen2 = await network.isRemotePortAvailable('example.com', {
port: 443,
retries: 3,
timeout: 5000,
});
2019-04-16 10:21:11 +02:00
```
2026-03-26 15:44:05 +00:00
---
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
### 📡 Ping & Traceroute
2025-07-31 22:04:20 +00:00
```typescript
2026-03-26 15:44:05 +00:00
// Simple ping
const ping = await network.ping('google.com');
console.log(`Alive: ${ping.alive}, RTT: ${ping.time} ms` );
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
// Multi-ping with statistics
const stats = await network.ping('google.com', { count: 10, timeout: 2000 });
console.log(`📊 min=${stats.min} avg=${stats.avg.toFixed(1)} max=${stats.max} loss=${stats.packetLoss}%` );
// Traceroute
const hops = await network.traceroute('google.com', { maxHops: 20 });
hops.forEach(hop => {
const rtt = hop.rtt === null ? '*' : `${hop.rtt} ms` ;
console.log(` ${hop.ttl}\t${hop.ip}\t${rtt}` );
2025-07-31 22:04:20 +00:00
});
```
2026-03-26 15:44:05 +00:00
> ⚠️ ICMP ping requires `CAP_NET_RAW` or appropriate `ping_group_range` sysctl on Linux.
2025-04-28 19:27:13 +00:00
2026-03-26 15:44:05 +00:00
---
2025-04-28 19:27:13 +00:00
2026-03-26 15:44:05 +00:00
### 🌍 DNS Resolution
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
Uses `@push.rocks/smartdns` with a system-first strategy and automatic DoH (DNS-over-HTTPS) fallback:
```typescript
const dns = await network.resolveDns('example.com');
console.log('A records:', dns.A); // ['93.184.216.34']
console.log('AAAA records:', dns.AAAA); // ['2606:2800:220:1:248:1893:25c8:1946']
dns.MX.forEach(mx => {
console.log(`📧 ${mx.exchange} (priority ${mx.priority})` );
});
2025-07-31 22:04:20 +00:00
```
2025-04-28 19:27:13 +00:00
2026-03-26 15:44:05 +00:00
---
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
### 🏥 HTTP/HTTPS Health Checks
2025-07-31 22:04:20 +00:00
```typescript
2026-03-26 15:44:05 +00:00
const health = await network.checkEndpoint('https://api.example.com/health', {
timeout: 5000,
rejectUnauthorized: true,
});
console.log(`Status: ${health.status}, RTT: ${health.rtt.toFixed(0)} ms` );
2025-07-31 22:04:20 +00:00
```
2026-03-26 15:44:05 +00:00
---
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
### 🖥️ Network Interfaces & Public IPs
2025-07-31 22:04:20 +00:00
```typescript
2026-03-26 15:44:05 +00:00
// All interfaces
const gateways = await network.getGateways();
Object.entries(gateways).forEach(([name, ifaces]) => {
console.log(`🔌 ${name}:` );
ifaces.forEach(i => console.log(` ${i.family}: ${i.address}` ));
});
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
// Default gateway
const gw = await network.getDefaultGateway();
if (gw) {
console.log(`🌐 Gateway IPv4: ${gw.ipv4.address}` );
}
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
// Public IPs (multiple fallback services: ipify, ident.me, seeip, icanhazip)
const publicIps = await network.getPublicIps();
console.log(`🌍 IPv4: ${publicIps.v4 || 'N/A'}` );
console.log(`🌍 IPv6: ${publicIps.v6 || 'N/A'}` );
2025-07-31 22:04:20 +00:00
```
2026-03-26 15:44:05 +00:00
---
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
### ⚡ Caching
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
Caching applies to `getGateways()` , `getPublicIps()` , and `getIpIntelligence()` :
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
```typescript
const network = new SmartNetwork({ cacheTtl: 60000 }); // 60s
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
const ips1 = await network.getPublicIps(); // fetches
const ips2 = await network.getPublicIps(); // cache hit ⚡
2025-07-31 22:04:20 +00:00
```
2026-03-26 15:44:05 +00:00
---
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
### 🚨 Error Handling
2025-07-31 22:04:20 +00:00
```typescript
2026-03-26 15:44:05 +00:00
import { SmartNetwork, NetworkError, TimeoutError } from '@push .rocks/smartnetwork';
2025-07-31 22:04:20 +00:00
try {
2025-09-12 13:30:09 +00:00
await network.isRemotePortAvailable('example.com', { protocol: 'udp' });
2025-07-31 22:04:20 +00:00
} catch (error) {
if (error instanceof NetworkError) {
2026-03-26 15:44:05 +00:00
console.error(`${error.message} (code: ${error.code})` ); // ENOTSUP
2025-07-31 22:04:20 +00:00
}
}
2025-04-28 19:27:13 +00:00
```
2026-03-26 15:44:05 +00:00
Error codes: `EINVAL` (invalid argument), `ENOTSUP` (not supported), `ETIMEOUT` (timeout).
2025-07-31 22:04:20 +00:00
2026-03-26 15:44:05 +00:00
---
### 🔧 Plugin Architecture
2025-07-31 22:04:20 +00:00
```typescript
2026-03-26 15:44:05 +00:00
class MyPlugin {
constructor(private network: SmartNetwork) {}
async doStuff() { /* ... */ }
2025-07-31 22:04:20 +00:00
}
2026-03-26 15:44:05 +00:00
SmartNetwork.registerPlugin('myPlugin', MyPlugin);
2025-09-12 17:59:06 +00:00
2026-03-26 15:44:05 +00:00
const PluginClass = SmartNetwork.pluginsRegistry.get('myPlugin');
const plugin = new PluginClass(network);
await plugin.doStuff();
2025-09-12 13:30:09 +00:00
2026-03-26 15:44:05 +00:00
SmartNetwork.unregisterPlugin('myPlugin');
2025-09-12 13:30:09 +00:00
```
2026-03-26 15:44:05 +00:00
---
2025-09-12 13:30:09 +00:00
2026-03-26 15:44:05 +00:00
### 📝 Custom Logging
Replace the default `console` logger:
2025-09-12 13:30:09 +00:00
```typescript
2026-03-26 15:44:05 +00:00
import { setLogger } from '@push .rocks/smartnetwork';
setLogger({
debug: (msg) => myLogger.debug(msg),
info: (msg) => myLogger.info(msg),
warn: (msg) => myLogger.warn(msg),
error: (msg) => myLogger.error(msg),
});
```
---
## 🛠️ Advanced Example: Network Monitor
```typescript
const monitor = async () => {
2025-09-12 13:30:09 +00:00
const network = new SmartNetwork({ cacheTtl: 30000 });
2026-03-26 15:44:05 +00:00
2025-09-12 13:30:09 +00:00
// Check critical services
const services = [
2026-03-26 15:44:05 +00:00
{ name: 'Web', host: 'example.com', port: 443 },
{ name: 'DB', host: 'db.internal', port: 5432 },
2025-09-12 13:30:09 +00:00
];
2026-03-26 15:44:05 +00:00
for (const svc of services) {
const up = await network.isRemotePortAvailable(svc.host, svc.port);
console.log(`${svc.name}: ${up ? '✅ UP' : '❌ DOWN'}` );
2025-09-12 13:30:09 +00:00
}
2026-03-26 15:44:05 +00:00
// Internet connectivity + latency
const ping = await network.ping('8.8.8.8');
console.log(`Internet: ${ping.alive ? '✅' : '❌'} (${ping.time} ms)` );
2025-09-12 13:30:09 +00:00
2026-03-26 15:44:05 +00:00
// Speed
const speed = await network.getSpeed();
console.log(`Speed: ⬇️ ${speed.downloadSpeed} / ⬆️ ${speed.uploadSpeed} Mbps` );
2025-09-12 13:30:09 +00:00
2026-03-26 15:44:05 +00:00
// Who am I?
const ips = await network.getPublicIps();
if (ips.v4) {
const intel = await network.getIpIntelligence(ips.v4);
console.log(`AS${intel.asn} (${intel.asnOrg}) — ${intel.city || intel.countryCode}` );
2025-09-12 13:30:09 +00:00
}
2026-03-26 15:44:05 +00:00
await network.stop();
2025-09-12 13:30:09 +00:00
};
2025-07-31 22:04:20 +00:00
```
2024-04-14 18:02:08 +02:00
2026-03-26 15:44:05 +00:00
## 📋 Full API Reference
| Method | Description | Requires Rust |
|--------|-------------|:---:|
| `start()` / `stop()` | Start/stop the Rust binary bridge | — |
| `getSpeed(opts?)` | Cloudflare speed test (download + upload) | No |
| `ping(host, opts?)` | ICMP ping with optional multi-ping stats | Yes |
| `traceroute(host, opts?)` | Hop-by-hop network path analysis | Yes |
| `isLocalPortUnused(port)` | Check if local port is free (IPv4+IPv6) | Yes |
| `findFreePort(start, end, opts?)` | Find available port in range | Yes |
| `isRemotePortAvailable(target, opts?)` | TCP port check on remote host | Yes |
| `getGateways()` | List all network interfaces | No |
| `getDefaultGateway()` | Get default gateway info | Yes |
| `getPublicIps()` | Discover public IPv4/IPv6 (4 fallback services) | No |
| `resolveDns(host)` | Resolve A, AAAA, MX records | No |
| `checkEndpoint(url, opts?)` | HTTP/HTTPS health check with RTT | No |
| `getIpIntelligence(ip)` | ASN + org + geo + RDAP registration | No |
2024-04-14 18:02:08 +02:00
## License and Legal Information
2026-03-26 15:44:05 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE ](./LICENSE ) file.
2024-04-14 18:02:08 +02:00
**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
2026-03-26 15:44:05 +00:00
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 or third parties, 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 or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
2019-11-19 23:00:37 +00:00
2024-04-14 18:02:08 +02:00
### Company Information
2019-11-19 23:00:37 +00:00
2026-03-26 15:44:05 +00:00
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
2019-04-16 10:21:11 +02:00
2026-03-26 15:44:05 +00:00
For any legal inquiries or further information, please contact us via email at hello@task .vc.
2019-04-16 10:21:11 +02:00
2026-03-26 15:44:05 +00:00
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.