How do I obtain the remote IP address for my Ethernet shield?
First learn how to search the forum...
The answer will present itself promptly.
I did do that before I made this post...
Nothing was helpful..
I did do that before I made this post...
Nothing was helpful..
What did you search for?
How did you miss this?
http://arduino.cc/forum/index.php/topic,82416.0.html
When I clicked your reply to answer, two posts down was a thread asking exactly the same thing completely answered. Hence my reply.
I saw that.
he's doing something else
"I wanted to record the remote IP address of clients using my Arduino as a web server."
I wanted to record the remote IP address of clients using my Arduino as a web server.
Well, first you have to obtain it. That's what the other thread is about. Once you have the remote IP, you can "record" it in whatever way you want.
I'm not sure I see where it says how to obtain a remote IP in the post
I added the following lines to the end of the EthernetClient.cpp file:
uint8_t *EthernetClient::getRemoteIP(uint8_t remoteIP[])
{
W5100.readSnDIPR(_sock, remoteIP);
return remoteIP;
}
So what do you suppose this function does?
That gets the remote IP of devices connected to your shield, right?
Yes.
Now, think with me for a second.
If you're a client, no one's going to connect to you. You are going to connect to someone. So, you already know who's on the other side, since you were the one connecting to it.
On the other hand, if you're a server, you have no idea who's connecting to you. That's where the getRemoteIP function comes in handy. So, I still don't understand why you think the previous thread isn't help for you at all.
Below is some code I copied/pasted to get the client IP address to print to the serial monitor and the web page. Still need to capture the client IP into a string.
//zoomkat 12-13-11
//client IP code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//
#include <SPI.h>
#include <Ethernet.h>
byte rip[4];
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString;
//////////////////////
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println("client IP test"); // so I can keep track of what is loaded
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store GET characters to string
readString += c;
}
//if HTTP request has ended
if (c == '\n') {
//////////// print to serial monitor
Serial.println("client IP address");
client.getRemoteIP(rip);
for (int bcount= 0; bcount < 4; bcount++)
{
Serial.print(rip[bcount], DEC);
if (bcount<3) Serial.print(".");
}
Serial.println();
///////////////
Serial.println(readString);
//now output HTML data header
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Arduino client IP test page</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Zoomkat's client IP test</H1>");
client.println("Client IP is </H1>");
////////////////// print to web page
client.getRemoteIP(rip);
for (int bcount= 0; bcount < 4; bcount++)
{
client.print(rip[bcount], DEC);
if (bcount<3) client.print(".");
}
/////////////////////////
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//clearing string for next read
readString="";
}
}
}
}
}
Thanks!
And sorry for being so annoying...