1

How does one retrieve the IP address of a socket.io connecting client?

This does not work in Socket.io v1.0: Get the client's IP address in socket.io . It returns undefined.

I tried doing a console.dir of the socket object, but this does not seem to work.

Community
  • 1
  • 1
jhtong
  • 1,529
  • 4
  • 23
  • 34

1 Answers1

0

How about this:

socket.request.socket.remoteAddress
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • uh returns undefined, even when in the `io.on 'connection'` block.. I did a `console.dir` dump and there doesnt 'seem' to be any such IP information listed. – jhtong Jan 06 '14 at 07:08
  • Hmm seems to work for me on the version posted on the repository. How did you install 1.0? – robertklep Jan 06 '14 at 07:32
  • I did the normal NPM install, from the Git repo. – jhtong Jan 06 '14 at 07:58
  • It returns an undefined. btw, did you test client / server codes on same machine? – jhtong Jan 06 '14 at 07:58
  • 1
    Yes, tried on same machine. When I try from a different machine it doesn't work for me either, but I also noticed that the transport being used is `polling`, which sounds strange. I think I would advice you to not use 1.0 until it's properly released :) – robertklep Jan 06 '14 at 08:15
  • I resolved to sending the IP over via a client field.. is not really crucial though if its spoofed. – jhtong Jan 06 '14 at 13:24