khoih-prog / WebSockets2_Generic

A WebSocket Server and Client library for Arduino, based on RFC6455, for writing modern Websockets applications. Now support ESP8266, ESP32 (including ESP32-S2 Saola, AI-Thinker ESP-12K, WT32_ETH01, etc.), nRF52, SAMD21, SAMD51, SAM DUE, STM32F/L/H/G/WB/MP1, Teensy, RP2040-based, etc. boards, with WiFiNINA, Teensy 4.1 NativeEthernet/QNEthernet, Ethernet W5x00 / ENC28J60 / LAN8742A / LAN8720, ESP8266 / ESP32-AT modules/shields, as well as SINRIC / Alexa / Google Home
GNU General Public License v3.0
81 stars 30 forks source link

Client IP address availability? #29

Closed 5b4wn closed 2 years ago

5b4wn commented 2 years ago

Thanks for a great library

I cant seem to find the following anywhere.

I am using the Teensy41_Server.ino websocket server is it possible to have a method to get the websocket client's IP address please? Or is there any other way to do so?

Eg client.remoteIP() ?

This is useful for IP filtering etc.

Many thanks Marios

khoih-prog commented 2 years ago

Thanks for your interest in and nice words about the library.

Currently, this library as well as its twin WebSockets_Generic Library, designed specifically for resource constraint MCUs, don't have that function to help in eliminating spams, attacks, etc using the help of IP filtering.

You can have these options:

  1. Use the Nodejs, etc. ws(s) server. Then the client IP is easily accessible. or example ws._socket.remoteAddress, ws._socket.remotePort
wss.on('connection', (ws, req) => 
{
    console.log(req.socket.remoteAddress);
});
  1. Write extra code, based on (Native)Ethernet / WiFi, etc to capture the client IP.
  2. Ask for enhancement (for ESP32/ESP8266) on ArduinoWebsockets Library, on which this library is based on.

I'm sorry I currently have no time to work on this issue and closing it now. If there are many more similar requests,I'll possibly reopen and work on the issue.

Good Luck,