SurferTim:
Hackers are a bit hesitant to show vulnerabilities in code, but I am a good hacker, not a bad one. I try to prevent a hack. This code will lock up every server example I have seen, including zoomkat's. Follow the serial monitor prompts. Do not close anything until you remove the CAT5 from your Arduino. Change the network settings to suit your localnet.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress server(192,168,1,254);
EthernetClient client;
void setup() {
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
delay(2000);
Serial.println("Ready. Enter l to lock");
}
void loop() {
if(Serial.available()) {
if(Serial.read() == 'l')
{
if(!getPage(server)) Serial.print("Fail ");
else Serial.print("Pass ");
}
}
}
byte getPage(IPAddress ipBuf)
{
Serial.print("connecting...");
if(client.connect(ipBuf,80))
{
Serial.print("connected");
// send request with no \r\n
client.print("GET / HTTP/1.1");
}
else
{
Serial.println("failed");
return 0;
}
Serial.println(" & locked. Remove CAT5 from the shield.");
return 1;
}
Thanks. I got one serial monitor prompt and nothing at all after that. And nothing showed up at either URL on my PC [at 192.168.1.177 (my 'static ip') or 192.168.1.254].
I guess I'm too naive and confused to even understand what you're trying to do here. It seems to me you've established router connection at one IPaddress, but are trying to access the server on another,
IPAddress ip(192,168,2,2);
IPAddress server(192,168,1,254);
Hopelessly lost, so probably best to forget my question, :-(.