import { Client } from 'ssh2'; const conn = new Client(); conn.on('ready', () => { console.log('=== 检查端口占用 ===\n'); conn.exec('netstat -tlnp | grep :80', (err, stream) => { if (err) { console.log('检查端口失败:', err.message); conn.end(); return; } stream.on('data', (data) => { console.log('80端口占用:', data.toString()); }); stream.on('close', () => { conn.exec('ps aux | grep nginx', (err, stream2) => { if (err) { console.log('检查nginx失败:', err.message); conn.end(); return; } stream2.on('data', (data) => { console.log('\nnginx进程:', data.toString()); }); stream2.on('close', () => { conn.exec('which nginx && nginx -v 2>/dev/null || echo "系统nginx未安装"', (err, stream3) => { if (err) { console.log('检查系统nginx失败:', err.message); conn.end(); return; } stream3.on('data', (data) => { console.log('\n系统nginx:', data.toString()); }); stream3.on('close', () => { conn.end(); }); }); }); }); }); }); }); conn.on('error', (err) => { console.log('连接错误:', err.message); }); conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' });