first commit
This commit is contained in:
commit
75f12b6daf
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
node_modules/
|
||||||
|
.env
|
||||||
|
test/
|
||||||
|
package-lock.json
|
||||||
100
index.js
Normal file
100
index.js
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
const speedTest = require('speedtest-net');
|
||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
|
async function runSpeedTest(serverId) {
|
||||||
|
const options = {
|
||||||
|
serverId,
|
||||||
|
acceptLicense: true,
|
||||||
|
acceptGdpr: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`Testing speed with server ID: ${serverId}, please wait...`);
|
||||||
|
const result = await speedTest(options);
|
||||||
|
|
||||||
|
// Format hasil
|
||||||
|
const output = {
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
ping: {
|
||||||
|
jitter: result.ping.jitter,
|
||||||
|
latency: result.ping.latency,
|
||||||
|
},
|
||||||
|
download: {
|
||||||
|
bandwidth: result.download.bandwidth,
|
||||||
|
bytes: result.download.bytes,
|
||||||
|
elapsed: result.download.elapsed,
|
||||||
|
},
|
||||||
|
upload: {
|
||||||
|
bandwidth: result.upload.bandwidth,
|
||||||
|
bytes: result.upload.bytes,
|
||||||
|
elapsed: result.upload.elapsed,
|
||||||
|
},
|
||||||
|
packetLoss: result.packetLoss,
|
||||||
|
isp: result.isp,
|
||||||
|
interface: {
|
||||||
|
internalIp: result.interface.internalIp,
|
||||||
|
name: result.interface.name,
|
||||||
|
macAddr: result.interface.macAddr,
|
||||||
|
isVpn: result.interface.isVpn,
|
||||||
|
externalIp: result.interface.externalIp,
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
id: result.server.id,
|
||||||
|
name: result.server.name,
|
||||||
|
location: result.server.location,
|
||||||
|
country: result.server.country,
|
||||||
|
host: result.server.host,
|
||||||
|
port: result.server.port,
|
||||||
|
ip: result.server.ip,
|
||||||
|
},
|
||||||
|
result: {
|
||||||
|
id: result.result.id,
|
||||||
|
url: result.result.url,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('Test complete. Result:');
|
||||||
|
console.log(JSON.stringify(output, null, 2));
|
||||||
|
return output;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error running speed test with server ID: ${serverId}:`, error.message);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendResultToServer(result) {
|
||||||
|
const url = 'https://raspberry.pandawa24jam.com/wbhkraspberry';
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'author': 'vedeom',
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('Sending result to server...');
|
||||||
|
const response = await axios.post(url, result, { headers });
|
||||||
|
console.log('Result successfully sent. Server response:');
|
||||||
|
console.log(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to send result to server:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
// Coba server pertama
|
||||||
|
const primaryServerId = 39296; // Gunadarma University
|
||||||
|
const result = await runSpeedTest(primaryServerId);
|
||||||
|
await sendResultToServer(result);
|
||||||
|
} catch (primaryError) {
|
||||||
|
console.warn('Primary server failed. Attempting backup server...');
|
||||||
|
|
||||||
|
// Jika server pertama gagal, coba server kedua
|
||||||
|
const backupServerId = 13039; // Server kedua
|
||||||
|
try {
|
||||||
|
const result = await runSpeedTest(backupServerId);
|
||||||
|
await sendResultToServer(result);
|
||||||
|
} catch (backupError) {
|
||||||
|
console.error('Backup server also failed. Please check your internet connection or server configurations.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
15
package.json
Normal file
15
package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "speedtest-client",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"description": "",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^1.7.9"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user