Get IP address from WebSocket in browser

2019-08-31 17:43发布

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.

I've examined the WebSocket object and the specification, and it appears that the url can be returned but not the IP.

How can the IP be retrieved from the WebSocket connection in a browser?

2条回答
Root(大扎)
2楼-- · 2019-08-31 17:46

It is not possible to derive the IP address based on a WebSocket object in a browser for security reasons.

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. Although, this would seriously undermine your security.

查看更多
时光不老,我们不散
3楼-- · 2019-08-31 18:02

AFAIK, there is no such way to get resolve IP from url, you may use external services, check http://www.fileformat.info/tool/rest/dns-json.htm

查看更多
登录 后发表回答