pinokiod 3.10.8 → 3.10.9

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 (2) hide show
  1. package/kernel/procs.js +50 -35
  2. package/package.json +1 -1
package/kernel/procs.js CHANGED
@@ -6,12 +6,18 @@ const platform = os.platform();
6
6
  class Procs {
7
7
  constructor () {
8
8
  console.log("Initializing procs")
9
+ this.cache = {}
9
10
  }
10
11
  async isHttp(localAddress) {
12
+ if (this.cache.hasOwnProperty(localAddress)) {
13
+ return this.cache[localAddress]
14
+ }
11
15
  try {
12
16
  await axios.head(`http://${localAddress}`, { timeout: 1000 });
17
+ this.cache[localAddress] = true
13
18
  return true;
14
19
  } catch (err) {
20
+ this.cache[localAddress] = false
15
21
  return false;
16
22
  }
17
23
  }
@@ -29,48 +35,57 @@ class Procs {
29
35
  for(let line of lines) {
30
36
  if (isWin) {
31
37
  // Skip headers
32
- if (!line.startsWith(' TCP')) continue;
33
- const parts = line.trim().split(/\s+/);
34
- const [ , localAddress, , state, pid ] = parts;
38
+ try {
39
+ if (!line.startsWith(' TCP')) continue;
40
+ const parts = line.trim().split(/\s+/);
41
+ const [ , localAddress, , state, pid ] = parts;
42
+
43
+ //if (state !== 'LISTENING') continue;
44
+ const chunks = localAddress.split(":")
45
+ const port = chunks.pop()
46
+ let ip = chunks.pop()
47
+ if (!ip || ip === "*") {
48
+ ip = "127.0.0.1:" + port
49
+ } else {
50
+ ip = localAddress
51
+ }
35
52
 
36
- //if (state !== 'LISTENING') return;
37
- let isHttp = await this.isHttp(localAddress)
38
- if (!isHttp) continue
39
- const chunks = localAddress.split(":")
40
- const port = chunks.pop()
41
- let ip = chunks.pop()
42
- if (!ip || ip === "*") {
43
- ip = "127.0.0.1:" + port
44
- } else {
45
- ip = localAddress
53
+ let isHttp = await this.isHttp(ip)
54
+ if (!isHttp) continue
55
+
56
+ if (pids.has(pid+"/"+port)) continue;
57
+ pids.add(pid+"/"+port)
58
+ results.push({ port, pid, ip });
59
+ } catch (e) {
46
60
  }
47
- if (pids.has(pid+"/"+port)) continue;
48
- pids.add(pid+"/"+port)
49
- results.push({ port, pid, ip });
50
61
  } else {
51
- //if (!/LISTEN/.test(line)) return;
52
- const parts = line.trim().split(/\s+/);
53
- const pid = parts[1];
62
+ // if (!/LISTEN/.test(line)) continue;
63
+ try {
64
+ const parts = line.trim().split(/\s+/);
65
+ const pid = parts[1];
66
+
67
+ const match = line.match(/([^\s]+:\d+)\s/);
68
+ const localAddress = match?.[1];
54
69
 
55
- const match = line.match(/([^\s]+:\d+)\s/);
56
- const localAddress = match?.[1];
70
+ const chunks = localAddress.split(":")
71
+ const port = chunks.pop()
72
+ let ip = chunks.pop()
73
+ if (!ip || ip === "*") {
74
+ ip = "127.0.0.1:" + port
75
+ } else {
76
+ ip = localAddress
77
+ }
57
78
 
58
- let isHttp = await this.isHttp(localAddress)
59
- if (!isHttp) continue;
79
+ let isHttp = await this.isHttp(ip)
80
+ if (!isHttp) continue;
60
81
 
61
- const chunks = localAddress.split(":")
62
- const port = chunks.pop()
63
- let ip = chunks.pop()
64
- if (!ip || ip === "*") {
65
- ip = "127.0.0.1:" + port
66
- } else {
67
- ip = localAddress
82
+ //const portMatch = line.match(/:(\d+)\s/);
83
+ //const port = portMatch?.[1];
84
+ if (pids.has(pid+"/"+port)) continue;
85
+ pids.add(pid+"/"+port)
86
+ if (pid && port) results.push({ port, pid, ip });
87
+ } catch (e) {
68
88
  }
69
- //const portMatch = line.match(/:(\d+)\s/);
70
- //const port = portMatch?.[1];
71
- if (pids.has(pid+"/"+port)) continue;
72
- pids.add(pid+"/"+port)
73
- if (pid && port) results.push({ port, pid, ip });
74
89
  }
75
90
  }
76
91
  callback(null, results);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.10.8",
3
+ "version": "3.10.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {