-->
Page 1 of 2

Read Target Ip

PostPosted: Sun Jun 05, 2016 4:04 am
by Hans53
Hi everyone
I had a Webserver running on an Arduino Uno using the “Ethercard” library together with “tinyFAT” SD library
There it was possible to get the target IP address, if a section was uncommented in the example code

/* uncomment this if you want to have printed the ip of the target browser
Serial.print("content send to ");
for(int i=30; i<34; i++) {
Serial.print(Ethernet::buffer[i]);
if (i<33) Serial.print(".");
}
Serial.println(" ");
*/

Is it possible to read the target IP using the “ESP8266WebServer”library?
The original web server in running perfectly on the ESP8266, but it would be real nice to know who is trying to access it
HansP

Re: Read Target Ip

PostPosted: Sun Jun 05, 2016 8:06 am
by martinayotte
With the ESP8266WebServer library, you can simply do a Serial.print(webserver.client.remoteIP().toString())

Re: Read Target Ip

PostPosted: Tue Jun 07, 2016 12:25 pm
by Hans53
martinayotte wrote:With the ESP8266WebServer library, you can simply do a Serial.print(webserver.client.remoteIP().toString())


Hi
I tried with this
But the code did not compile



#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

Server declaration
ESP8266WebServer server(80);

In setup
void setup() {
server.onNotFound(handleNotFound);
}

void handleNotFound(){
String HTTP_req = server.uri();
if (loadFromSdCard(server.uri())) return;
if(HTTP_req.indexOf("ajax_switch") > -1){
Serial.print(server.client.remoteIP().toString());
handle_Ajax(1);
}

Error message:
Arduino: 1.6.9 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 4M (Min SPIFFS), ck, Disabled, None"
C:\Users\Hans\Documents\Arduino\ESP_Ajax_Server\ESP_Ajax_Server.ino: In function 'void handleNotFound()':
ESP_Ajax_Server:141: error: 'server.ESP8266WebServer::client' does not have class type
Serial.print(server.client.remoteIP().toString());
exit status 1
'server.ESP8266WebServer::client' does not have class type

Re: Read Target Ip

PostPosted: Tue Jun 07, 2016 1:11 pm
by martinayotte
Sorry, I did a typo there by forgetting parenthesis to client method, it should be :
Code: Select allserver.client().remoteIP().toString()