70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 检查网络配置 ===\n');
|
|
|
|
conn.exec('netstat -tlnp | grep -E ":80|:443|:4000"', (err, stream) => {
|
|
if (err) {
|
|
console.log('端口检查失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream.on('data', (data) => {
|
|
console.log('端口监听:', data.toString());
|
|
});
|
|
|
|
stream.on('close', () => {
|
|
conn.exec('iptables -L INPUT -n | head -20', (err, stream2) => {
|
|
if (err) {
|
|
console.log('防火墙检查失败:', err.message);
|
|
} else {
|
|
stream2.on('data', (data2) => {
|
|
console.log('\n防火墙规则:', data2.toString());
|
|
});
|
|
}
|
|
|
|
stream2.on('close', () => {
|
|
conn.exec('curl -s http://127.0.0.1:4000/ | head -5', (err, stream3) => {
|
|
if (err) {
|
|
console.log('本地访问失败:', err.message);
|
|
} else {
|
|
stream3.on('data', (data3) => {
|
|
console.log('\n本地访问:', data3.toString());
|
|
}
|
|
}
|
|
|
|
stream3.on('close', () => {
|
|
conn.exec('curl -s http://localhost:4000/api/prices | head -3', (err, stream4) => {
|
|
if (err) {
|
|
console.log('本地API失败:', err.message);
|
|
} else {
|
|
stream4.on('data', (data4) => {
|
|
console.log('\n本地API:', data4.toString());
|
|
}
|
|
}
|
|
|
|
stream4.on('close', () => {
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |