简体   繁体   English

从浏览器中的WebSocket获取IP地址

[英]Get IP address from WebSocket in browser

I need to get the IP address of a WebSocket and compare it to other already connected WebSockets to prevent redundant connections because the list of server addresses for this application are retrieved from potentially malicious sources. 我需要获取WebSocket的IP地址并将其与其他已连接的WebSocket进行比较,以防止冗余连接,因为此应用程序的服务器地址列表是从潜在的恶意源中检索到的。

I've examined the WebSocket object and the specification , and it appears that the url can be returned but not the IP. 我检查了WebSocket对象和规范 ,似乎可以返回url但不能返回IP。

How can the IP be retrieved from the WebSocket connection in a browser? 如何从浏览器的WebSocket连接中检索IP?

AFAIK,没有这种方法可以从URL获取解析IP,您可以使用外部服务,请查看http://www.fileformat.info/tool/rest/dns-json.htm

It is not possible to derive the IP address based on a WebSocket object in a browser for security reasons. 出于安全原因,在浏览器中无法基于WebSocket对象派生IP地址。

In case you are connecting to your own server, you can setup the WebSockets to communicate the IP with the browser when the connection is first established. 如果要连接到自己的服务器,则可以在首次建立连接时将WebSocket设置为与浏览器通信IP。 Although, this would seriously undermine your security. 虽然,这会严重破坏您的安全性。

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

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