i need help in accessing the web server remotely over internet not in lan

i am an newbie to the arduino i have found a working code to control relays through lan webserver. i need to access that web page on internet were now i can only access it on my local area network.

WebServerSwitchingV04_06.ino (28.9 KB)

Usually people use a dynamic IP service like http://www.noip.com/ and similar to track dynamic IP situations. Use the forum search feature (upper right of this page) for previous post.

hmm. thanku for reply. an you provide me a sample code.

Web server code that produces a web page with three different types of URL addressing.

//zoomkat 04-10-15
//simple button GET with iframe code
//open serial monitor to see what the arduino receives
//use the ' instead of " in html ilnes 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //ethernet shield mac address
byte ip[] = { 
  192, 168, 1, 102 }; // arduino 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(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("server test no-ip 04-10-15"); // 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 characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

            //now output HTML data header
          if(readString.indexOf('?') >=0) { //don't send new page
            client.println("HTTP/1.1 204 Zoomkat\r\n\r\n");
          }
          else {
            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 GET test page</TITLE>");
            client.println("</HEAD>");
            client.println("<BODY>");

            client.println("<H1>Zoomkat's simple Arduino button</H1>");
            client.println("Arduino served LAN: <a href='/?on1' target='inlineframe'>ON</a>"); 
            client.println("<a href='/?off' target='inlineframe'>OFF</a>

"); 

            client.println("Remote served LAN: <a href='http://192.168.1.102:84/?on1' target='inlineframe'>ON</a>"); 
            client.println("<a href='http://192.168.1.102:84/?off' target='inlineframe'>OFF</a>

"); 

            client.println("Remote served no-ip: <a href='http://zoomkat.no-ip.org:84/?on1' target='inlineframe'>ON</a>"); 
            client.println("<a href='http://zoomkat.no-ip.org:84/?off' target='inlineframe'>OFF</a>"); 

            client.println("<IFRAME name=inlineframe style='display:none'>");          
            client.println("</IFRAME>");

            client.println("</BODY>");
            client.println("</HTML>");
          }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

Making it work is simple (and totally unrelated to Arduino) - just find your IP address with whatismyip.com and configure port forwarding on your router (refer to the documentation for your router - this is beyond the scope of these forums. Depending on your ISP and where you live, you may also have to change settings on your cable modem through a web interface to tell it to let the port through as well - refer to appropriate documentation) such that the port that the webserver on the Arduino is running gets forwarded to the IP address you selected. If option is given, it's TCP.

Then you can use that IP address (the external one, from whatismyip etc) as the IP for the server and connect from anywhere.

However, whether you want to do something like that is another matter, since you've made no provisions for security! That (coupled with the limited resources of arduino processors which preclude effective crypto) is why there are so many services for controlling arduino and similar remotely - people use something like that so their arduino doesn't have to be exposed to incoming connections (which might be malicious)