showip/app.js

21 lines
417 B
JavaScript
Raw Normal View History

2021-04-09 16:56:13 +01:00
const express = require('express')
const { Resolver } = require('dns').promises
const app = express()
const r = new Resolver()
app.get('/', async (req, res) => {
res.header('Content-type: text/plain')
const ip = req.connection.remoteAddress
let host
try {
host = await r.reverse(ip)
} catch(err) {
console.log(err.message)
host = 'ERR'
}
res.send(`${ip}\n${host}\n`)
})
app.listen(18080)