简体   繁体   English

Javascript - 从本地主机上的请求中获取外部 IP 地址

[英]Javascript - Get external IP address from request made on localhost

I am currently in the process of developing a feature that that calls out to an external service to get location information based on the client's IP.我目前正在开发一项功能,该功能调用外部服务以根据客户端的 IP 获取位置信息。

In my express node server, I am pulling the ip with req.ip , which from what I've read elsewhere is the correct way to do it.在我的快速节点服务器中,我正在使用 req.ip 拉req.ip ,从我在其他地方读到的内容来看,这是正确的方法。 However, because I am running the server / client locally, the IP address on the request is my local host.但是,因为我在本地运行服务器/客户端,所以请求上的 IP 地址是我的本地主机。

Is there anyway to make the request from my client, which is running locally, to put my external IP into the request so I can validate that my full feature is working properly?无论如何,是否可以从本地运行的客户端发出请求,将我的外部 IP 放入请求中,以便我可以验证我的全部功能是否正常工作?

Connect to your server with your public IP rather than localhost使用您的公共 IP 而不是 localhost 连接到您的服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM