feat(smartnetwork): Add randomizable port search and switch DNS resolution to @push.rocks/smartdns; export smartdns and update docs
This commit is contained in:
22
readme.md
22
readme.md
@@ -17,9 +17,9 @@ pnpm install @push.rocks/smartnetwork --save
|
||||
### ✨ Key Features
|
||||
|
||||
- **🏎️ Speed Testing** - Measure download/upload speeds using Cloudflare's infrastructure
|
||||
- **🔌 Port Management** - Check local/remote port availability, find free ports
|
||||
- **🔌 Port Management** - Check local/remote port availability, find free ports (sequential or random)
|
||||
- **📡 Connectivity Testing** - Ping hosts, trace routes, check endpoints
|
||||
- **🌍 DNS Operations** - Resolve A, AAAA, and MX records
|
||||
- **🌍 DNS Operations** - Resolve A, AAAA, and MX records with smart local/remote resolution
|
||||
- **🔍 Network Discovery** - Get network interfaces, gateways, public IPs
|
||||
- **⚡ Performance Caching** - Built-in caching for expensive operations
|
||||
- **🔧 Plugin Architecture** - Extend functionality with custom plugins
|
||||
@@ -87,7 +87,7 @@ Automatically discover available ports:
|
||||
|
||||
```typescript
|
||||
const findFreePort = async () => {
|
||||
// Find a free port between 3000 and 3100
|
||||
// Find a free port between 3000 and 3100 (sequential - returns first available)
|
||||
const freePort = await network.findFreePort(3000, 3100);
|
||||
|
||||
if (freePort) {
|
||||
@@ -95,6 +95,10 @@ const findFreePort = async () => {
|
||||
} else {
|
||||
console.log('😢 No free ports available in range');
|
||||
}
|
||||
|
||||
// Find a random free port in range (useful to avoid port conflicts)
|
||||
const randomPort = await network.findFreePort(3000, 3100, { randomize: true });
|
||||
console.log(`🎲 Random free port: ${randomPort}`);
|
||||
};
|
||||
```
|
||||
|
||||
@@ -175,7 +179,7 @@ hops.forEach(hop => {
|
||||
|
||||
### 🌍 DNS Operations
|
||||
|
||||
Resolve various DNS record types:
|
||||
Resolve various DNS record types using @push.rocks/smartdns with intelligent resolution strategy:
|
||||
|
||||
```typescript
|
||||
const dnsRecords = await network.resolveDns('example.com');
|
||||
@@ -188,8 +192,14 @@ console.log(' AAAA records:', dnsRecords.AAAA); // IPv6 addresses
|
||||
dnsRecords.MX.forEach(mx => {
|
||||
console.log(` 📧 Mail server: ${mx.exchange} (priority: ${mx.priority})`);
|
||||
});
|
||||
|
||||
// Properly handles local hostnames (localhost, etc.)
|
||||
const localDns = await network.resolveDns('localhost');
|
||||
console.log(' Localhost:', localDns.A); // Returns ['127.0.0.1']
|
||||
```
|
||||
|
||||
*DNS resolution uses a `prefer-system` strategy: tries system resolver first (respects /etc/hosts and local DNS), with automatic fallback to Cloudflare DoH for external domains.*
|
||||
|
||||
### 🏥 HTTP/HTTPS Health Checks
|
||||
|
||||
Monitor endpoint availability and response times:
|
||||
@@ -321,6 +331,10 @@ interface SmartNetworkOptions {
|
||||
cacheTtl?: number; // Cache TTL in milliseconds
|
||||
}
|
||||
|
||||
interface IFindFreePortOptions {
|
||||
randomize?: boolean; // If true, returns a random free port instead of the first one
|
||||
}
|
||||
|
||||
interface Hop {
|
||||
ttl: number; // Time to live
|
||||
ip: string; // IP address of the hop
|
||||
|
Reference in New Issue
Block a user