chopper-port-hunter 1.0.1 ā 1.0.2
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.
Potentially problematic release.
This version of chopper-port-hunter might be problematic. Click here for more details.
- package/index.js +62 -37
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,44 +1,69 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
3
|
import { exec } from "child_process";
|
|
4
|
+
import { promisify } from "util";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
6
|
+
const execAsync = promisify(exec);
|
|
7
|
+
|
|
8
|
+
async function hunt() {
|
|
9
|
+
console.log("\nšø Chopper Port Hunter šø\nAll bow to the pink hat!\n");
|
|
10
|
+
|
|
11
|
+
const { action } = await inquirer.prompt([
|
|
12
|
+
{
|
|
13
|
+
type: "rawlist",
|
|
14
|
+
name: "action",
|
|
15
|
+
message: "What do you want to do?",
|
|
16
|
+
choices: ["Fix a stuck port", "Go to sleep"],
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
if (action.includes("sleep")) {
|
|
21
|
+
console.log("\nāµ Chopper sits onboard the Thousand Sunny...");
|
|
22
|
+
console.log("Puts his pink hat over his face to block the sun... š¤\n");
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { port } = await inquirer.prompt([
|
|
27
|
+
{
|
|
28
|
+
type: "input",
|
|
29
|
+
name: "port",
|
|
30
|
+
message: "Which port needs medicine?",
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const num = parseInt(port, 10);
|
|
35
|
+
|
|
36
|
+
if (isNaN(num)) {
|
|
37
|
+
console.log("\nā Chopper: Wait, that is not a number! I cannot parse it!");
|
|
38
|
+
return hunt();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (num < 1024) {
|
|
42
|
+
console.log(
|
|
43
|
+
"\nā Chopper: Stop! Hidden system ports under 1024 are too dangerous!",
|
|
44
|
+
);
|
|
45
|
+
return hunt();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (num > 65535) {
|
|
49
|
+
console.log(
|
|
50
|
+
"\nā Chopper: Wow, that number is way too huge! It does not exist!",
|
|
51
|
+
);
|
|
52
|
+
return hunt();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const cmd = `powershell -NoProfile -NonInteractive -WindowStyle Hidden -Command "Stop-Process -Id (Get-NetTCPConnection -LocalPort ${num} -ErrorAction SilentlyContinue).OwningProcess -Force -ErrorAction SilentlyContinue"`;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await execAsync(cmd, { windowsHide: true });
|
|
59
|
+
console.log(`\nš Success! I cured it! Port ${num} is healthy and free!`);
|
|
60
|
+
} catch {
|
|
61
|
+
console.log(
|
|
62
|
+
"\nšØ The scopes are clear. This port has no active infections!",
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return hunt();
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
hunt();
|