How to get client IP address with WebSocket (websockets/ws) library in Node.js?

后端 未结 2 1308
-上瘾入骨i
-上瘾入骨i 2021-01-30 16:38

I cannot find the client IP parameter on the client object.

2条回答
  •  礼貌的吻别
    2021-01-30 17:21

    Got this from printing the keys in the socket object:

    > ws._socket.address()
      { port: 8081,
        family: 2,
        address: '127.0.0.1' }
    
    > ws._socket.remoteAddress
      '74.125.224.194'
    
    > ws._socket.remotePort
      41435
    

    I don't have any documentation so I'm not sure how well this is supported across versions :/

提交回复
热议问题