const express = require("express"); const app = express();

app.get("/", (req, res) => { const ip = req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.socket.remoteAddress; res.send("我的 IP 地址:" + ip); })

app.listen(4000, () => { console.log('Server running at http://localhost:4000/'); });

您获取到的 IP 地址为 :::1 是因为您的应用程序正在运行在本地主机上,而 ::1 是本地主机的回环地址(即 localhost 或 127.0.0.1)。

Node.js 获取 IP 地址:解决 :::1 问题

原文地址: https://www.cveoy.top/t/topic/qhJx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录