Skip to content Skip to sidebar Skip to footer

Get IP Of Connection In Socket.io 1.4.5

I would like to know how to get the IP of a user when they connect to the server n socket.io. I have tried using this code which is supposed to log the connection address and port

Solution 1:

The IP address is in socket.handshake.address, not socket.handshake.address.address.


Though none of this appears to be documented in socket.io, you can get the remote IP address and the remote port with these:

socket.request.connection.remoteAddress
socket.request.connection.remotePort

When I connect to a socket.io server from another computer on my LAN, I see these output from those above two settings:

::ffff:192.168.1.56
51210

This is correctly giving you the IP address and the port of the remote computer that is connecting to your server. The IP address ::ffff:192.168.1.56 is an IPv4 mapped address. You will have to handle that form of address on some systems.


Post a Comment for "Get IP Of Connection In Socket.io 1.4.5"