56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
const { Client } = require('ssh2');
|
|
|
|
const config = {
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
};
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', async () => {
|
|
console.log('SSH连接成功');
|
|
|
|
try {
|
|
console.log('\n=== 测试JS资源 ===');
|
|
await executeCommand('curl -s -o /dev/null -w "JS: %{http_code}, Size: %{size_download} bytes\n" http://hs.yifenbao.cn/h5/assets/index-CFIPh5xV.js');
|
|
|
|
console.log('\n=== 测试CSS资源 ===');
|
|
await executeCommand('curl -s -o /dev/null -w "CSS: %{http_code}, Size: %{size_download} bytes\n" http://hs.yifenbao.cn/h5/assets/index-Cqbf_rwD.css');
|
|
|
|
console.log('\n=== 测试API接口 ===');
|
|
await executeCommand('curl -s -o /dev/null -w "API: %{http_code}\n" http://hs.yifenbao.cn/api/prices');
|
|
|
|
console.log('\n=== 测试API内容 ===');
|
|
await executeCommand('curl -s http://hs.yifenbao.cn/api/prices');
|
|
|
|
} catch (error) {
|
|
console.error('测试失败:', error.message);
|
|
} finally {
|
|
conn.end();
|
|
}
|
|
});
|
|
|
|
function executeCommand(cmd) {
|
|
return new Promise((resolve) => {
|
|
conn.exec(cmd, (err, stream) => {
|
|
if (err) {
|
|
console.error('命令执行错误:', err.message);
|
|
resolve();
|
|
return;
|
|
}
|
|
|
|
stream.stdout.on('data', (data) => process.stdout.write(data));
|
|
stream.stderr.on('data', (data) => process.stdout.write(data));
|
|
|
|
stream.on('close', () => resolve());
|
|
});
|
|
});
|
|
}
|
|
|
|
conn.on('error', (err) => {
|
|
console.error('SSH连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect(config); |