76 lines
2.0 KiB
JavaScript
76 lines
2.0 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 检查防火墙 ===\n');
|
|
|
|
conn.exec('ufw status 2>/dev/null || iptables -L -n | head -30', (err, stream) => {
|
|
if (err) {
|
|
console.log('防火墙检查失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream.on('data', (data) => {
|
|
console.log('防火墙状态:', data.toString());
|
|
});
|
|
|
|
stream.on('close', () => {
|
|
conn.exec('netstat -tlnp | grep :443', (err, stream2) => {
|
|
if (err) {
|
|
console.log('端口检查失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream2.on('data', (data) => {
|
|
console.log('\n443端口:', data.toString());
|
|
});
|
|
|
|
stream2.on('close', () => {
|
|
conn.exec('curl -s -m 5 https://api.ipify.org', (err, stream3) => {
|
|
if (err) {
|
|
console.log('获取公网IP失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream3.on('data', (data) => {
|
|
console.log('\n公网IP:', data.toString());
|
|
|
|
conn.exec(`curl -s -m 5 https://${data.toString().trim()}/`, (err, stream4) => {
|
|
if (err) {
|
|
console.log('\n公网访问失败:', err.message);
|
|
} else {
|
|
stream4.on('data', (data2) => {
|
|
console.log('\n公网访问成功:', data2.toString().substring(0, 200));
|
|
});
|
|
}
|
|
|
|
stream4.on('close', () => {
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
|
|
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'
|
|
}); |