scripting-cli 1.2.4 → 1.2.5

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.
@@ -7,6 +7,7 @@ exports.startServer = startServer;
7
7
  const express_1 = __importDefault(require("express"));
8
8
  const http_1 = __importDefault(require("http"));
9
9
  const socket_io_1 = require("socket.io");
10
+ const os_1 = __importDefault(require("os"));
10
11
  const ip_1 = __importDefault(require("ip"));
11
12
  const bonjour_1 = __importDefault(require("bonjour"));
12
13
  const chalk_1 = __importDefault(require("chalk"));
@@ -18,6 +19,78 @@ const app = (0, express_1.default)();
18
19
  const server = http_1.default.createServer(app);
19
20
  const io = new socket_io_1.Server(server);
20
21
  const bonjour = (0, bonjour_1.default)();
22
+ // Keywords to identify VPN/virtual network adapters that should be excluded
23
+ const VIRTUAL_ADAPTER_KEYWORDS = [
24
+ 'virtual',
25
+ 'vpn',
26
+ 'vethernet',
27
+ 'vmware',
28
+ 'vmnet',
29
+ 'vbox',
30
+ 'virtualbox',
31
+ 'docker',
32
+ 'wsl',
33
+ 'loopback',
34
+ 'hamachi',
35
+ 'tunngle',
36
+ 'cloudflare',
37
+ 'warp',
38
+ 'tailscale',
39
+ 'zerotier'
40
+ ];
41
+ // Preferred adapter names for real network interfaces
42
+ const PREFERRED_ADAPTER_KEYWORDS = [
43
+ 'ethernet',
44
+ 'eth',
45
+ 'wi-fi',
46
+ 'wifi',
47
+ 'wlan',
48
+ 'en0',
49
+ 'en1'
50
+ ];
51
+ /**
52
+ * Get the local network IP address, filtering out VPN and virtual adapters.
53
+ * Prioritizes real network adapters (Ethernet, Wi-Fi) over virtual ones.
54
+ */
55
+ function getLocalNetworkIP() {
56
+ const interfaces = os_1.default.networkInterfaces();
57
+ const results = [];
58
+ for (const [name, addrs] of Object.entries(interfaces)) {
59
+ if (!addrs)
60
+ continue;
61
+ const lowerName = name.toLowerCase();
62
+ // Skip virtual/VPN adapters
63
+ if (VIRTUAL_ADAPTER_KEYWORDS.some(keyword => lowerName.includes(keyword))) {
64
+ continue;
65
+ }
66
+ for (const addr of addrs) {
67
+ // Only consider non-internal IPv4 addresses
68
+ if (addr.family === 'IPv4' && !addr.internal) {
69
+ // Skip certain IP ranges typically used by VPNs
70
+ // 198.18.0.0/15 is reserved for network benchmark testing (Cloudflare WARP uses this)
71
+ // 100.64.0.0/10 is Carrier-grade NAT (Tailscale uses this)
72
+ const ip = addr.address;
73
+ const firstOctet = parseInt(ip.split('.')[0], 10);
74
+ const secondOctet = parseInt(ip.split('.')[1], 10);
75
+ if (firstOctet === 198 && (secondOctet === 18 || secondOctet === 19)) {
76
+ continue; // Skip 198.18.0.0/15
77
+ }
78
+ if (firstOctet === 100 && secondOctet >= 64 && secondOctet <= 127) {
79
+ continue; // Skip 100.64.0.0/10
80
+ }
81
+ // Determine priority (lower is better)
82
+ let priority = 10;
83
+ if (PREFERRED_ADAPTER_KEYWORDS.some(keyword => lowerName.includes(keyword))) {
84
+ priority = 1;
85
+ }
86
+ results.push({ name, address: ip, priority });
87
+ }
88
+ }
89
+ }
90
+ // Sort by priority and return the best match
91
+ results.sort((a, b) => a.priority - b.priority);
92
+ return results.length > 0 ? results[0].address : null;
93
+ }
21
94
  function startServer({ port, noAutoOpen, startBonjourService }) {
22
95
  // console.log("port", port, "noAutoOpen", noAutoOpen);
23
96
  const PORT = port ?? 3000;
@@ -31,7 +104,7 @@ function startServer({ port, noAutoOpen, startBonjourService }) {
31
104
  (0, util_1.createVSCodeSettings)(); // Create vscode settings.json when the server starts
32
105
  (0, util_1.ensureScriptsDirectory)(); // Ensure the scripts directory exists
33
106
  // await migrateOldFiles(); // Migrate old files to the scripts directory
34
- const ipAddress = ip_1.default.address();
107
+ const ipAddress = getLocalNetworkIP() ?? ip_1.default.address();
35
108
  const address = `http://${ipAddress}:${PORT}`;
36
109
  if (startBonjourService) {
37
110
  console.log(`Server listening on ${chalk_1.default.bold.blue(address)}\n\n${chalk_1.default.yellow('You can select this server in the Scripting app to connect')}.\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripting-cli",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "This plugin integrates the desktop editor synchronization feature of the Scripting app.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -2,6 +2,7 @@
2
2
  import express from 'express';
3
3
  import http from 'http';
4
4
  import { Server as SocketIOServer } from 'socket.io';
5
+ import os from 'os';
5
6
  import ip from 'ip';
6
7
  import Bonjour from 'bonjour';
7
8
  import chalk from 'chalk';
@@ -15,6 +16,88 @@ const server = http.createServer(app);
15
16
  const io = new SocketIOServer(server);
16
17
  const bonjour = Bonjour();
17
18
 
19
+ // Keywords to identify VPN/virtual network adapters that should be excluded
20
+ const VIRTUAL_ADAPTER_KEYWORDS = [
21
+ 'virtual',
22
+ 'vpn',
23
+ 'vethernet',
24
+ 'vmware',
25
+ 'vmnet',
26
+ 'vbox',
27
+ 'virtualbox',
28
+ 'docker',
29
+ 'wsl',
30
+ 'loopback',
31
+ 'hamachi',
32
+ 'tunngle',
33
+ 'cloudflare',
34
+ 'warp',
35
+ 'tailscale',
36
+ 'zerotier'
37
+ ];
38
+
39
+ // Preferred adapter names for real network interfaces
40
+ const PREFERRED_ADAPTER_KEYWORDS = [
41
+ 'ethernet',
42
+ 'eth',
43
+ 'wi-fi',
44
+ 'wifi',
45
+ 'wlan',
46
+ 'en0',
47
+ 'en1'
48
+ ];
49
+
50
+ /**
51
+ * Get the local network IP address, filtering out VPN and virtual adapters.
52
+ * Prioritizes real network adapters (Ethernet, Wi-Fi) over virtual ones.
53
+ */
54
+ function getLocalNetworkIP(): string | null {
55
+ const interfaces = os.networkInterfaces();
56
+ const results: { name: string; address: string; priority: number }[] = [];
57
+
58
+ for (const [name, addrs] of Object.entries(interfaces)) {
59
+ if (!addrs) continue;
60
+
61
+ const lowerName = name.toLowerCase();
62
+
63
+ // Skip virtual/VPN adapters
64
+ if (VIRTUAL_ADAPTER_KEYWORDS.some(keyword => lowerName.includes(keyword))) {
65
+ continue;
66
+ }
67
+
68
+ for (const addr of addrs) {
69
+ // Only consider non-internal IPv4 addresses
70
+ if (addr.family === 'IPv4' && !addr.internal) {
71
+ // Skip certain IP ranges typically used by VPNs
72
+ // 198.18.0.0/15 is reserved for network benchmark testing (Cloudflare WARP uses this)
73
+ // 100.64.0.0/10 is Carrier-grade NAT (Tailscale uses this)
74
+ const ip = addr.address;
75
+ const firstOctet = parseInt(ip.split('.')[0], 10);
76
+ const secondOctet = parseInt(ip.split('.')[1], 10);
77
+
78
+ if (firstOctet === 198 && (secondOctet === 18 || secondOctet === 19)) {
79
+ continue; // Skip 198.18.0.0/15
80
+ }
81
+ if (firstOctet === 100 && secondOctet >= 64 && secondOctet <= 127) {
82
+ continue; // Skip 100.64.0.0/10
83
+ }
84
+
85
+ // Determine priority (lower is better)
86
+ let priority = 10;
87
+ if (PREFERRED_ADAPTER_KEYWORDS.some(keyword => lowerName.includes(keyword))) {
88
+ priority = 1;
89
+ }
90
+
91
+ results.push({ name, address: ip, priority });
92
+ }
93
+ }
94
+ }
95
+
96
+ // Sort by priority and return the best match
97
+ results.sort((a, b) => a.priority - b.priority);
98
+ return results.length > 0 ? results[0].address : null;
99
+ }
100
+
18
101
  export function startServer({ port, noAutoOpen, startBonjourService }: {
19
102
  port: number | undefined
20
103
  noAutoOpen: boolean | undefined
@@ -39,7 +122,7 @@ export function startServer({ port, noAutoOpen, startBonjourService }: {
39
122
 
40
123
  // await migrateOldFiles(); // Migrate old files to the scripts directory
41
124
 
42
- const ipAddress = ip.address()
125
+ const ipAddress = getLocalNetworkIP() ?? ip.address();
43
126
  const address = `http://${ipAddress}:${PORT}`;
44
127
 
45
128
  if (startBonjourService) {