/** * IP Ping Monitor * * 1. Install dependencies: * npm install express ping cors * 2. Run: * node ip-ping-monitor.js * 3. Open your browser at http://localhost:3000 * * You can deploy this on any Node‑compatible host. The server exposes a small REST endpoint * /api/ping?host= that performs an ICMP ping and responds with JSON. */ const express = require('express'); const cors = require('cors'); const ping = require('ping'); const app = express(); const PORT = process.env.PORT || 3000; app.use(cors()); app.use(express.json()); // --- REST endpoint ---------------------------------------------------- app.get('/api/ping', async (req, res) => { const host = req.query.host; if (!host) return res.status(400).json({ error: 'Query param "host" missing' }); try { const result = await ping.promise.probe(host, { timeout: 3 }); res.json({ host, up: result.alive, time: result.time || null }); } catch (err) { res.json({ host, up: false, error: err.message }); } }); // --- Single‑page frontend -------------------------------------------- app.get('/', (req, res) => { res.send(htmlPage); }); const htmlPage = ` IP Ping Monitor

🌐 IP Ping Monitor

HostStatusLatency (ms)Last checked
`; app.listen(PORT, () => console.log(`\u2705 IP Ping Monitor running on http://localhost:${PORT}`));