Go Down

Topic: Web server client IP (Read 2214 times) previous topic - next topic


Dec 02, 2012, 02:12 pm Last Edit: Dec 03, 2012, 03:34 am by SurferTim Reason: 1
It may be helpful to some if the ethernet library included a way to retrieve the client ip when using the server code. It can be used as a primitive firewall, preventing unauthorized client access. My library code changes to do this are already working.
The modified ethernet library code is attached to reply #1. It uses the new ip address format (IPAddress) in the same manner as the other ip functions in Ethernet.cpp.

Code: [Select]
IPAddress clientIP = client.remoteIP();

edit: This is the total code added. Nothing else changed.

Code added to EthernetClient module:
Code: [Select]
// EthernetClient.h
IPAddress remoteIP();

// EthernetClient.cpp
IPAddress EthernetClient::remoteIP() {
   return Ethernet.remoteIP(_sock);

Code added to Ethernet module:
Code: [Select]
// Ethernet.h
IPAddress remoteIP(uint8_t s);

// Ethernet.cpp
IPAddress EthernetClass::remoteIP(uint8_t s) {
 IPAddress ret;
 return ret;

Go Up