Go Down

Topic: Web server client IP (Read 1 time) previous topic - next topic

SurferTim

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.
http://arduino.cc/forum/index.php/topic,135082.0.html
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;
 W5100.readSnDIPR(s,ret.raw_address());
 return ret;
}


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy