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.

Files changed (2) hide show
  1. package/index.js +62 -37
  2. 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
- function hunt() {
6
- console.log("\n🌸 CHOPPER PORT HUNTER 🦌\nAll bow to the pink hat!\n");
7
-
8
- inquirer
9
- .prompt([
10
- {
11
- type: "input",
12
- name: "port",
13
- message: "Enter port to clear:",
14
- },
15
- ])
16
- .then(({ port }) => {
17
- const num = parseInt(port, 10);
18
-
19
- if (isNaN(num) || num < 1024 || num > 65535) {
20
- console.log(
21
- "\nāŒ Invalid port entry! Rules: more than 1024, and below 65535. No commas",
22
- );
23
- return hunt();
24
- }
25
-
26
- const cmd = `powershell -WindowStyle Hidden -Command "Stop-Process -Id (Get-NetTCPConnection -LocalPort ${num} -ErrorAction SilentlyContinue).OwningProcess -Force -PassThru -ErrorAction SilentlyContinue"`;
27
-
28
- exec(cmd, (err, stdout) => {
29
- if (err || !stdout.trim()) {
30
- console.log(
31
- "šŸ’Ø Active target not found. This port is already clear!",
32
- );
33
- return;
34
- }
35
-
36
- const report = stdout.replace(/[\r\n]+/g, " ").trim();
37
- console.log(
38
- `\nšŸŽ‰ Success!\n\n ${report}\n\n🌸 Port ${num} is completely free!`,
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chopper-port-hunter",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "license": "CC-BY-NC-ND-4.0",
5
5
  "type": "module",
6
6
  "bin": {