获取node.js应用程序的公共IP地址 [英] Get Public IP Address for node.js application

查看:231
本文介绍了获取node.js应用程序的公共IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何node.js模块可用于获取客户端计算机发出请求的公共IP地址?我不是指IPv4或IPv6,当你去 http://www.whatismyip时,我需要你得到的公共IP。 .com /

Is there any node.js module that can be used to get the public IP address of the client's computer making a request? I don't mean IPv4 or IPv6, I need the public IP like you get when you go to http://www.whatismyip.com/

我试过 req.connection.remoteAddress; 但它没有返回公共知识产权。它必须是公开的,所以我可以根据IP地址找到城市。

I have tried req.connection.remoteAddress; but it doesn't return the public IP. It has to be public so I can locate the city based on the IP address.

谢谢:)

推荐答案

我知道这个老问题,但现在你可以使用 http://whatismyipaddress.com/ api 获取IP。只需向bot.whatismyipaddress.com发送请求并获得结果。

I know this old question, but now you can use http://whatismyipaddress.com/api to get IP. Just send request to bot.whatismyipaddress.com and get result.

var http = require('http');
http.get('http://bot.whatismyipaddress.com', function(res){
    res.setEncoding('utf8');
    res.on('data', function(chunk){
        console.log(chunk);
    });
});

这篇关于获取node.js应用程序的公共IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆