20 lines
629 B
JavaScript
20 lines
629 B
JavaScript
const express = require('express');
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Middleware to get client IP
|
|
app.get('/', (req, res) => {
|
|
// Get client IP from various possible headers (for proxy support)
|
|
const clientIp = req.headers['x-forwarded-for']?.split(',')[0].trim() ||
|
|
req.headers['x-real-ip'] ||
|
|
req.socket.remoteAddress ||
|
|
req.connection.remoteAddress;
|
|
|
|
res.send(clientIp);
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`IP Pinger service running on port ${PORT}`);
|
|
console.log(`Visit http://localhost:${PORT} to see your IP`);
|
|
});
|