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?
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.
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