@fanboynz/network-scanner 2.0.26 → 2.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/nettools.js +140 -92
  2. package/nwss.js +2 -2
  3. package/package.json +1 -1
package/lib/nettools.js CHANGED
@@ -357,7 +357,7 @@ async function whoisLookup(domain, timeout = 10000, whoisServer = null, debugMod
357
357
  * @param {number} whoisDelay - Delay in milliseconds before whois requests (default: 2000)
358
358
  * @returns {Promise<Object>} Object with success status and output/error
359
359
  */
360
- async function whoisLookupWithRetry(domain, timeout = 10000, whoisServer = null, debugMode = false, retryOptions = {}, whoisDelay = 4000, logFunc = null) {
360
+ async function whoisLookupWithRetry(domain, timeout = 10000, whoisServer = null, debugMode = false, retryOptions = {}, whoisDelay = 8000, logFunc = null) {
361
361
  const {
362
362
  maxRetries = 3,
363
363
  timeoutMultiplier = 1.5,
@@ -367,7 +367,6 @@ async function whoisLookupWithRetry(domain, timeout = 10000, whoisServer = null,
367
367
  } = retryOptions;
368
368
 
369
369
  let serversToTry = [];
370
- let currentTimeout = timeout;
371
370
 
372
371
  // Build list of servers to try
373
372
  if (whoisServer) {
@@ -390,88 +389,124 @@ async function whoisLookupWithRetry(domain, timeout = 10000, whoisServer = null,
390
389
  }
391
390
 
392
391
  let lastError = null;
393
- let attemptCount = 0;
392
+ let totalAttempts = 0;
393
+ let serversAttempted = [];
394
394
 
395
395
  if (debugMode) {
396
396
  if (logFunc) {
397
397
  logFunc(`${messageColors.highlight('[whois-retry]')} Starting whois lookup for ${domain} with ${serversToTry.length} server(s) to try`);
398
398
  logFunc(`${messageColors.highlight('[whois-retry]')} Servers: [${serversToTry.map(s => s || 'default').join(', ')}]`);
399
- logFunc(`${messageColors.highlight('[whois-retry]')} Retry settings: maxRetries=${maxRetries}, timeoutMultiplier=${timeoutMultiplier}, retryOnTimeout=${retryOnTimeout}, retryOnError=${retryOnError}`);
399
+ logFunc(`${messageColors.highlight('[whois-retry]')} Retry settings: maxRetries=${maxRetries} per server, timeoutMultiplier=${timeoutMultiplier}, retryOnTimeout=${retryOnTimeout}, retryOnError=${retryOnError}`);
400
400
  } else {
401
401
  console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Starting whois lookup for ${domain} with ${serversToTry.length} server(s) to try`));
402
402
  console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Servers: [${serversToTry.map(s => s || 'default').join(', ')}]`));
403
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Retry settings: maxRetries=${maxRetries}, timeoutMultiplier=${timeoutMultiplier}, retryOnTimeout=${retryOnTimeout}, retryOnError=${retryOnError}`));
403
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Retry settings: maxRetries=${maxRetries} per server, timeoutMultiplier=${timeoutMultiplier}, retryOnTimeout=${retryOnTimeout}, retryOnError=${retryOnError}`));
404
404
  }
405
405
  }
406
406
 
407
- for (const server of serversToTry) {
408
- attemptCount++;
407
+ // Try each server with retry logic
408
+ for (let serverIndex = 0; serverIndex < serversToTry.length; serverIndex++) {
409
+ const server = serversToTry[serverIndex];
410
+ let currentTimeout = timeout;
411
+ let retryCount = 0;
412
+ serversAttempted.push(server);
409
413
 
410
414
  if (debugMode) {
411
415
  const serverName = server || 'default';
412
416
  if (logFunc) {
413
- logFunc(`${messageColors.highlight('[whois-retry]')} Attempt ${attemptCount}/${serversToTry.length}: trying server ${serverName} (timeout: ${currentTimeout}ms)`);
417
+ logFunc(`${messageColors.highlight('[whois-retry]')} Server ${serverIndex + 1}/${serversToTry.length}: ${serverName} (max ${maxRetries} attempts)`);
414
418
  } else {
415
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Attempt ${attemptCount}/${serversToTry.length}: trying server ${serverName} (timeout: ${currentTimeout}ms)`));
419
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Server ${serverIndex + 1}/${serversToTry.length}: ${serverName} (max ${maxRetries} attempts)`));
416
420
  }
417
421
  }
418
422
 
419
- // Add delay between retry attempts to prevent rate limiting
420
- if (attemptCount > 1) {
421
- if (whoisDelay > 0) {
422
- if (debugMode) {
423
- if (logFunc) {
424
- logFunc(`${messageColors.highlight('[whois-retry]')} Adding ${whoisDelay}ms delay before retry attempt...`);
425
- } else {
426
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Adding ${whoisDelay}ms delay before retry attempt...`));
427
- }
428
- }
429
- await new Promise(resolve => setTimeout(resolve, whoisDelay));
430
- }
423
+ // Retry this server up to maxRetries times
424
+ while (retryCount < maxRetries) {
425
+ totalAttempts++;
426
+ const attemptNum = retryCount + 1;
431
427
 
432
- } else if (whoisDelay > 0) {
433
- // Add initial delay on first attempt if configured
434
428
  if (debugMode) {
429
+ const serverName = server || 'default';
435
430
  if (logFunc) {
436
- logFunc(`${messageColors.highlight('[whois-retry]')} Adding ${whoisDelay}ms delay to prevent rate limiting...`);
431
+ logFunc(`${messageColors.highlight('[whois-retry]')} Attempt ${attemptNum}/${maxRetries} on server ${serverName} (timeout: ${currentTimeout}ms)`);
437
432
  } else {
438
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Adding ${whoisDelay}ms delay to prevent rate limiting...`));
433
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Attempt ${attemptNum}/${maxRetries} on server ${serverName} (timeout: ${currentTimeout}ms)`));
439
434
  }
440
435
  }
441
- await new Promise(resolve => setTimeout(resolve, whoisDelay));
442
- } else if (debugMode) {
443
- // Log when delay is skipped due to whoisDelay being 0
444
- if (logFunc) {
445
- logFunc(`${messageColors.highlight('[whois-retry]')} Skipping delay (whoisDelay: ${whoisDelay}ms)`);
446
- } else {
447
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Skipping delay (whoisDelay: ${whoisDelay}ms)`));
448
- }
449
- }
450
-
451
- try {
452
- const result = await whoisLookup(domain, currentTimeout, server, debugMode, logFunc);
453
436
 
454
- if (result.success) {
437
+ // Add progressive delay between retries (but not before first attempt on any server)
438
+ if (retryCount > 0 && whoisDelay > 0) {
439
+ // Progressive delay: base delay * retry attempt number + extra delay
440
+ // Attempt 2: base delay * 1 + 4000ms = 8000ms + 4000ms = 12000ms
441
+ // Attempt 3: base delay * 2 + 6000ms = 16000ms + 6000ms = 22000ms
442
+ // Attempt 4+: base delay * 3 + 6000ms = 24000ms + 6000ms = 30000ms (if maxRetries > 3)
443
+ const delayMultiplier = Math.min(retryCount, 3);
444
+ const baseDelay = whoisDelay * delayMultiplier;
445
+
446
+ // Add extra delay based on retry attempt
447
+ let extraDelay = 0;
448
+ if (retryCount === 1) {
449
+ extraDelay = 4000; // Extra 4 seconds for 2nd attempt
450
+ } else if (retryCount >= 2) {
451
+ extraDelay = 6000; // Extra 6 seconds for 3rd+ attempts
452
+ }
453
+
454
+ const actualDelay = baseDelay + extraDelay;
455
+
456
+ if (debugMode) {
457
+ if (logFunc) {
458
+ logFunc(`${messageColors.highlight('[whois-retry]')} Adding ${actualDelay}ms progressive delay before retry ${retryCount + 1} (base: ${baseDelay}ms + extra: ${extraDelay}ms)...`);
459
+ } else {
460
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Adding ${actualDelay}ms progressive delay before retry ${retryCount + 1} (base: ${baseDelay}ms + extra: ${extraDelay}ms)...`));
461
+ }
462
+ }
463
+ await new Promise(resolve => setTimeout(resolve, actualDelay));
464
+ } else if (serverIndex > 0 && retryCount === 0 && whoisDelay > 0) {
465
+ // Add delay before trying a new server (but not the very first server)
455
466
  if (debugMode) {
456
467
  if (logFunc) {
457
- logFunc(`${messageColors.highlight('[whois-retry]')} SUCCESS on attempt ${attemptCount}/${serversToTry.length} using server ${result.whoisServer || 'default'}`);
468
+ logFunc(`${messageColors.highlight('[whois-retry]')} Adding ${whoisDelay}ms delay before trying new server...`);
458
469
  } else {
459
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} SUCCESS on attempt ${attemptCount}/${serversToTry.length} using server ${result.whoisServer || 'default'}`));
470
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Adding ${whoisDelay}ms delay before trying new server...`));
460
471
  }
461
472
  }
473
+ await new Promise(resolve => setTimeout(resolve, whoisDelay));
474
+ } else if (debugMode && whoisDelay === 0) {
475
+ // Log when delay is skipped due to whoisDelay being 0
476
+ if (logFunc) {
477
+ logFunc(`${messageColors.highlight('[whois-retry]')} Skipping delay (whoisDelay: ${whoisDelay}ms)`);
478
+ } else {
479
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Skipping delay (whoisDelay: ${whoisDelay}ms)`));
480
+ }
481
+ }
482
+
483
+ try {
484
+ const result = await whoisLookup(domain, currentTimeout, server, debugMode, logFunc);
462
485
 
463
- // Add retry info to result
464
- return {
465
- ...result,
466
- retryInfo: {
467
- totalAttempts: attemptCount,
468
- maxAttempts: serversToTry.length,
469
- serversAttempted: serversToTry.slice(0, attemptCount),
470
- finalServer: result.whoisServer,
471
- retriedAfterFailure: attemptCount > 1
486
+ if (result.success) {
487
+ if (debugMode) {
488
+ if (logFunc) {
489
+ logFunc(`${messageColors.highlight('[whois-retry]')} SUCCESS on attempt ${attemptNum}/${maxRetries} for server ${result.whoisServer || 'default'} (total attempts: ${totalAttempts})`);
490
+ } else {
491
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} SUCCESS on attempt ${attemptNum}/${maxRetries} for server ${result.whoisServer || 'default'} (total attempts: ${totalAttempts})`));
492
+ }
472
493
  }
473
- };
474
- } else {
494
+
495
+ // Add retry info to result
496
+ return {
497
+ ...result,
498
+ retryInfo: {
499
+ totalAttempts: totalAttempts,
500
+ maxAttempts: serversToTry.length * maxRetries,
501
+ serversAttempted: serversAttempted,
502
+ finalServer: result.whoisServer,
503
+ retriedAfterFailure: totalAttempts > 1,
504
+ serverRetries: retryCount,
505
+ serverIndex: serverIndex
506
+ }
507
+ };
508
+ }
509
+
475
510
  // Determine if we should retry based on error type
476
511
  const shouldRetry = (result.isTimeout && retryOnTimeout) || (!result.isTimeout && retryOnError);
477
512
 
@@ -479,72 +514,85 @@ async function whoisLookupWithRetry(domain, timeout = 10000, whoisServer = null,
479
514
  const serverName = result.whoisServer || 'default';
480
515
  const errorType = result.isTimeout ? 'TIMEOUT' : 'ERROR';
481
516
  if (logFunc) {
482
- logFunc(`${messageColors.highlight('[whois-retry]')} ${errorType} on attempt ${attemptCount}/${serversToTry.length} with server ${serverName}: ${result.error}`);
517
+ logFunc(`${messageColors.highlight('[whois-retry]')} ${errorType} on attempt ${attemptNum}/${maxRetries} with server ${serverName}: ${result.error}`);
483
518
  } else {
484
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} ${errorType} on attempt ${attemptCount}/${serversToTry.length} with server ${serverName}: ${result.error}`));
519
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} ${errorType} on attempt ${attemptNum}/${maxRetries} with server ${serverName}: ${result.error}`));
485
520
  }
486
521
 
487
- if (attemptCount < serversToTry.length) {
522
+ if (retryCount < maxRetries - 1) {
488
523
  if (shouldRetry) {
489
524
  if (logFunc) {
490
- logFunc(`${messageColors.highlight('[whois-retry]')} Will retry with next server...`);
525
+ logFunc(`${messageColors.highlight('[whois-retry]')} Will retry attempt ${attemptNum + 1}/${maxRetries} on same server...`);
491
526
  } else {
492
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Will retry with next server...`));
527
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Will retry attempt ${attemptNum + 1}/${maxRetries} on same server...`));
493
528
  }
494
529
  } else {
495
530
  if (logFunc) {
496
- logFunc(`${messageColors.highlight('[whois-retry]')} Skipping retry (retryOn${result.isTimeout ? 'Timeout' : 'Error'}=${shouldRetry})`);
531
+ logFunc(`${messageColors.highlight('[whois-retry]')} Skipping retry on same server (retryOn${result.isTimeout ? 'Timeout' : 'Error'}=${shouldRetry})`);
497
532
  } else {
498
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Skipping retry (retryOn${result.isTimeout ? 'Timeout' : 'Error'}=${shouldRetry})`));
533
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Skipping retry on same server (retryOn${result.isTimeout ? 'Timeout' : 'Error'}=${shouldRetry})`));
499
534
  }
500
535
  }
536
+ } else if (serverIndex < serversToTry.length - 1) {
537
+ if (logFunc) {
538
+ logFunc(`${messageColors.highlight('[whois-retry]')} Max retries reached for server, will try next server...`);
539
+ } else {
540
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} Max retries reached for server, will try next server...`));
541
+ }
501
542
  }
502
543
  }
503
544
 
504
545
  lastError = result;
505
546
 
506
- // If this is the last server or we shouldn't retry this error type, break
507
- if (attemptCount >= serversToTry.length || !shouldRetry) {
547
+ // If this is the last retry for this server or we shouldn't retry this error type, break to next server
548
+ if (retryCount >= maxRetries - 1 || !shouldRetry) {
508
549
  break;
509
550
  }
510
551
 
511
- // Increase timeout for next attempt
552
+ // Increase timeout for next retry attempt on same server
553
+ retryCount++;
512
554
  currentTimeout = Math.round(currentTimeout * timeoutMultiplier);
513
- }
514
- } catch (error) {
515
- if (debugMode) {
516
- const serverName = server || 'default';
517
- if (logFunc) {
518
- logFunc(`${messageColors.highlight('[whois-retry]')} EXCEPTION on attempt ${attemptCount}/${serversToTry.length} with server ${serverName}: ${error.message}`);
519
- } else {
520
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} EXCEPTION on attempt ${attemptCount}/${serversToTry.length} with server ${serverName}: ${error.message}`));
555
+
556
+ } catch (error) {
557
+ if (debugMode) {
558
+ const serverName = server || 'default';
559
+ if (logFunc) {
560
+ logFunc(`${messageColors.highlight('[whois-retry]')} EXCEPTION on attempt ${attemptNum}/${maxRetries} with server ${serverName}: ${error.message}`);
561
+ } else {
562
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} EXCEPTION on attempt ${attemptNum}/${maxRetries} with server ${serverName}: ${error.message}`));
563
+ }
521
564
  }
565
+
566
+ lastError = {
567
+ success: false,
568
+ error: error.message,
569
+ domain: domain,
570
+ whoisServer: server,
571
+ isTimeout: error.message.includes('timeout'),
572
+ duration: 0
573
+ };
574
+
575
+ // For exceptions, only retry if it's a retryable error type
576
+ const isRetryableException = error.message.includes('timeout') ||
577
+ error.message.includes('ECONNRESET') ||
578
+ error.message.includes('ENOTFOUND');
579
+
580
+ if (retryCount >= maxRetries - 1 || !isRetryableException) {
581
+ break;
582
+ }
583
+
584
+ retryCount++;
585
+ currentTimeout = Math.round(currentTimeout * timeoutMultiplier);
522
586
  }
523
-
524
- lastError = {
525
- success: false,
526
- error: error.message,
527
- domain: domain,
528
- whoisServer: server,
529
- isTimeout: error.message.includes('timeout'),
530
- duration: 0
531
- };
532
-
533
- // Continue to next server unless this is the last one
534
- if (attemptCount >= serversToTry.length) {
535
- break;
536
- }
537
-
538
- currentTimeout = Math.round(currentTimeout * timeoutMultiplier);
539
587
  }
540
588
  }
541
589
 
542
590
  // All attempts failed
543
591
  if (debugMode) {
544
592
  if (logFunc) {
545
- logFunc(`${messageColors.highlight('[whois-retry]')} FINAL FAILURE: All ${attemptCount} attempts failed for ${domain}`);
593
+ logFunc(`${messageColors.highlight('[whois-retry]')} FINAL FAILURE: All ${totalAttempts} attempts failed for ${domain} across ${serversAttempted.length} server(s)`);
546
594
  } else {
547
- console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} FINAL FAILURE: All ${attemptCount} attempts failed for ${domain}`));
595
+ console.log(formatLogMessage('debug', `${messageColors.highlight('[whois-retry]')} FINAL FAILURE: All ${totalAttempts} attempts failed for ${domain} across ${serversAttempted.length} server(s)`));
548
596
  }
549
597
  if (lastError) {
550
598
  if (logFunc) {
@@ -559,11 +607,11 @@ async function whoisLookupWithRetry(domain, timeout = 10000, whoisServer = null,
559
607
  return {
560
608
  ...lastError,
561
609
  retryInfo: {
562
- totalAttempts: attemptCount,
563
- maxAttempts: serversToTry.length,
564
- serversAttempted: serversToTry.slice(0, attemptCount),
610
+ totalAttempts: totalAttempts,
611
+ maxAttempts: serversToTry.length * maxRetries,
612
+ serversAttempted: serversAttempted,
565
613
  finalServer: lastError?.whoisServer || null,
566
- retriedAfterFailure: attemptCount > 1,
614
+ retriedAfterFailure: totalAttempts > 1,
567
615
  allAttemptsFailed: true
568
616
  }
569
617
  };
@@ -1357,4 +1405,4 @@ module.exports = {
1357
1405
  getCommonWhoisServers,
1358
1406
  suggestWhoisServers,
1359
1407
  execWithTimeout // Export for testing
1360
- };
1408
+ };
package/nwss.js CHANGED
@@ -1,4 +1,4 @@
1
- // === Network scanner script (nwss.js) v2.0.26 ===
1
+ // === Network scanner script (nwss.js) v2.0.27 ===
2
2
 
3
3
  // puppeteer for browser automation, fs for file system operations, psl for domain parsing.
4
4
  // const pLimit = require('p-limit'); // Will be dynamically imported
@@ -143,7 +143,7 @@ const { navigateWithRedirectHandling, handleRedirectTimeout } = require('./lib/r
143
143
  const { monitorBrowserHealth, isBrowserHealthy, isQuicklyResponsive, performGroupWindowCleanup, performRealtimeWindowCleanup, trackPageForRealtime, updatePageUsage, cleanupPageBeforeReload } = require('./lib/browserhealth');
144
144
 
145
145
  // --- Script Configuration & Constants ---
146
- const VERSION = '2.0.26'; // Script version
146
+ const VERSION = '2.0.27'; // Script version
147
147
 
148
148
  // get startTime
149
149
  const startTime = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanboynz/network-scanner",
3
- "version": "2.0.26",
3
+ "version": "2.0.27",
4
4
  "description": "A Puppeteer-based network scanner for analyzing web traffic, generating adblock filter rules, and identifying third-party requests. Features include fingerprint spoofing, Cloudflare bypass, content analysis with curl/grep, and multiple output formats.",
5
5
  "main": "nwss.js",
6
6
  "scripts": {